Skip to content

Commit 596a003

Browse files
authored
Merge pull request #262 from aether-framework/bugfix/137-147-150-161-185-195-200-210-219-220-cleanup-batch
Enhance UTF-8 handling and error refinement in modules
2 parents a2aff99 + 3bd9fad commit 596a003

10 files changed

Lines changed: 37 additions & 23 deletions

File tree

aether-datafixers-cli/src/main/java/de/splatgames/aether/datafixers/cli/command/MigrateCommand.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
import java.io.File;
4444
import java.io.IOException;
45+
import java.nio.charset.StandardCharsets;
4546
import java.nio.file.Files;
4647
import java.nio.file.Path;
4748
import java.nio.file.StandardCopyOption;
@@ -498,7 +499,7 @@ public Integer call() {
498499
if (this.generateReport && !reportBuilder.isEmpty()) {
499500
final String reportContent = reportBuilder.toString();
500501
if (this.reportFile != null) {
501-
Files.writeString(this.reportFile.toPath(), reportContent);
502+
Files.writeString(this.reportFile.toPath(), reportContent, StandardCharsets.UTF_8);
502503
} else {
503504
System.err.println(reportContent);
504505
}
@@ -569,7 +570,7 @@ private <T> MigrationResult processFile(
569570
}
570571

571572
// Read input (strip UTF-8 BOM if present)
572-
String content = Files.readString(inputFile.toPath());
573+
String content = Files.readString(inputFile.toPath(), StandardCharsets.UTF_8);
573574
if (content.startsWith("\uFEFF")) {
574575
content = content.substring(1);
575576
}
@@ -674,9 +675,9 @@ private void writeOutput(@NotNull final File inputFile, @NotNull final String co
674675

675676
if (this.output.isDirectory()) {
676677
final Path outPath = this.output.toPath().resolve(inputFile.getName());
677-
Files.writeString(outPath, content);
678+
Files.writeString(outPath, content, StandardCharsets.UTF_8);
678679
} else if (this.inputFiles.size() == 1) {
679-
Files.writeString(this.output.toPath(), content);
680+
Files.writeString(this.output.toPath(), content, StandardCharsets.UTF_8);
680681
} else {
681682
throw new IllegalArgumentException(
682683
"Output must be a directory when multiple input files are specified");
@@ -689,7 +690,7 @@ private void writeOutput(@NotNull final File inputFile, @NotNull final String co
689690
final Path tempPath = Files.createTempFile(
690691
inputFile.toPath().getParent(), "migrate_", ".tmp");
691692
try {
692-
Files.writeString(tempPath, content);
693+
Files.writeString(tempPath, content, StandardCharsets.UTF_8);
693694
if (this.backup) {
694695
final String timestamp = ZonedDateTime.now(ZoneOffset.UTC)
695696
.format(DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'"));

aether-datafixers-cli/src/main/java/de/splatgames/aether/datafixers/cli/command/ValidateCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
import java.io.File;
3838
import java.io.IOException;
39+
import java.nio.charset.StandardCharsets;
3940
import java.nio.file.Files;
4041
import java.util.List;
4142
import java.util.concurrent.Callable;
@@ -328,7 +329,7 @@ private <T> ValidationResult validateFile(
328329
if (fileSize > 100 * 1024 * 1024) {
329330
throw new IOException("File exceeds maximum size (100MB): " + file);
330331
}
331-
String content = Files.readString(file.toPath());
332+
String content = Files.readString(file.toPath(), StandardCharsets.UTF_8);
332333
if (content.startsWith("\uFEFF")) {
333334
content = content.substring(1);
334335
}

aether-datafixers-cli/src/main/java/de/splatgames/aether/datafixers/cli/format/YamlSnakeYamlFormatHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.jetbrains.annotations.NotNull;
2929
import org.yaml.snakeyaml.DumperOptions;
3030
import org.yaml.snakeyaml.Yaml;
31+
import org.yaml.snakeyaml.error.YAMLException;
3132

3233
/**
3334
* Format handler for YAML using the SnakeYAML library.
@@ -174,7 +175,7 @@ public Object parse(@NotNull final String content) {
174175
throw new FormatParseException("YAML parsed to null");
175176
}
176177
return result;
177-
} catch (final Exception e) {
178+
} catch (final YAMLException | ClassCastException e) {
178179
throw new FormatParseException("Failed to parse YAML: " + e.getMessage(), e);
179180
}
180181
}

aether-datafixers-codec/src/main/java/de/splatgames/aether/datafixers/codec/json/gson/GsonOps.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ public DataResult<Stream<Pair<JsonElement, JsonElement>>> getMapEntries(
784784
return DataResult.success(
785785
object.entrySet().stream()
786786
.map(entry -> Pair.of(
787-
(JsonElement) new JsonPrimitive(entry.getKey()),
787+
new JsonPrimitive(entry.getKey()),
788788
entry.getValue()
789789
))
790790
);

aether-datafixers-core/src/main/java/de/splatgames/aether/datafixers/core/fix/DataFixerBuilder.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,7 @@ public void registerAll(@NotNull final TypeReference type, @NotNull final Iterab
155155
public DataFixerBuilder addFix(@NotNull final TypeReference type, @NotNull final DataFix<?> fix) {
156156
Preconditions.checkNotNull(type, "type must not be null");
157157
Preconditions.checkNotNull(fix, "fix must not be null");
158-
Preconditions.checkArgument(
159-
fix.fromVersion().compareTo(fix.toVersion()) <= 0,
160-
"fix.fromVersion must be <= fix.toVersion"
161-
);
162-
158+
// Version ordering validation is performed by DataFixRegistry.register()
163159
this.registry.register(type, fix);
164160
return this;
165161
}

aether-datafixers-core/src/main/java/de/splatgames/aether/datafixers/core/fix/SimpleSystemDataFixerContext.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,26 @@ private SimpleSystemDataFixerContext() {
6363

6464
@Override
6565
public void info(@NotNull final String message, @Nullable final Object... args) {
66-
System.out.printf("[INFO] " + message + "%n", args);
66+
System.out.println("[INFO] " + formatMessage(message, args));
6767
}
6868

6969
@Override
7070
public void warn(@NotNull final String message, @Nullable final Object... args) {
71-
System.out.printf("[WARN] " + message + "%n", args);
71+
System.err.println("[WARN] " + formatMessage(message, args));
72+
}
73+
74+
private static String formatMessage(final String message, final Object[] args) {
75+
if (args == null || args.length == 0) {
76+
return message;
77+
}
78+
final StringBuilder result = new StringBuilder(message);
79+
for (final Object arg : args) {
80+
final int idx = result.indexOf("{}");
81+
if (idx < 0) {
82+
break;
83+
}
84+
result.replace(idx, idx + 2, String.valueOf(arg));
85+
}
86+
return result.toString();
7287
}
7388
}

aether-datafixers-core/src/main/java/de/splatgames/aether/datafixers/core/fix/Slf4jDataFixerContext.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,15 @@ public Slf4jDataFixerContext(@NotNull final Logger logger) {
112112
@Override
113113
public void info(@NotNull final String message, @Nullable final Object... args) {
114114
Preconditions.checkNotNull(message, "message must not be null");
115-
if (this.logger.isInfoEnabled()) {
116-
this.logger.info(formatMessage(message, args));
117-
}
115+
// Delegate directly to SLF4J which handles {} placeholder formatting lazily
116+
this.logger.info(message, args);
118117
}
119118

120119
@Override
121120
public void warn(@NotNull final String message, @Nullable final Object... args) {
122121
Preconditions.checkNotNull(message, "message must not be null");
123-
if (this.logger.isWarnEnabled()) {
124-
this.logger.warn(formatMessage(message, args));
125-
}
122+
// Delegate directly to SLF4J which handles {} placeholder formatting lazily
123+
this.logger.warn(message, args);
126124
}
127125

128126
/**

aether-datafixers-spring-boot-starter/src/main/java/de/splatgames/aether/datafixers/spring/AetherDataFixersProperties.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ public String getDomainTag() {
522522
* @throws NullPointerException if domainTag is {@code null}
523523
*/
524524
public void setDomainTag(@NotNull final String domainTag) {
525+
Preconditions.checkArgument(!domainTag.isEmpty(), "domainTag must not be empty");
525526
this.domainTag = domainTag;
526527
}
527528
}

aether-datafixers-spring-boot-starter/src/main/java/de/splatgames/aether/datafixers/spring/autoconfigure/DataFixerAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ private static AetherDataFixer createFixer(
353353
*/
354354
@SuppressFBWarnings(
355355
value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE",
356-
justification = "Null check for getCurrentVersion() is performed before access on line 363."
356+
justification = "Null check for Field.get() result is performed before access via isAssignableFrom check."
357357
)
358358
@NotNull
359359
private static DataVersion resolveVersion(

aether-datafixers-testkit/src/main/java/de/splatgames/aether/datafixers/testkit/TestDataBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import java.util.LinkedHashMap;
3131
import java.util.Map;
32+
import java.util.Objects;
3233
import java.util.function.Consumer;
3334
import java.util.stream.Stream;
3435

@@ -288,7 +289,7 @@ public TestDataBuilder<T> put(@NotNull final String key, final short value) {
288289
public TestDataBuilder<T> put(@NotNull final String key, @NotNull final Dynamic<T> value) {
289290
Preconditions.checkNotNull(key, "key must not be null");
290291
Preconditions.checkNotNull(value, "value must not be null");
291-
Preconditions.checkArgument(this.ops == value.ops(),
292+
Preconditions.checkArgument(Objects.equals(this.ops, value.ops()),
292293
"Dynamic uses different DynamicOps");
293294
this.ensureObjectMode();
294295
this.fields.put(key, value);

0 commit comments

Comments
 (0)