Skip to content

Commit 0d088b1

Browse files
committed
Optimize SchemaValidator to dynamically determine max schema version and enforce stricter error handling with orElseThrow usage.
1 parent e313f74 commit 0d088b1

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

  • aether-datafixers-schema-tools/src/main/java/de/splatgames/aether/datafixers/schematools/validation

aether-datafixers-schema-tools/src/main/java/de/splatgames/aether/datafixers/schematools/validation/SchemaValidator.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,14 @@ public static SchemaValidator forBootstrap(@NotNull final DataFixerBootstrap boo
190190

191191
// Bootstrap into capturing registries
192192
final SchemaRegistry schemaRegistry = new SimpleSchemaRegistry();
193-
final DataFixerBuilder fixerBuilder = new DataFixerBuilder(new DataVersion(Integer.MAX_VALUE));
194-
195193
bootstrap.registerSchemas(schemaRegistry);
194+
195+
final int maxVersion = schemaRegistry.stream()
196+
.mapToInt(s -> s.version().getVersion())
197+
.max()
198+
.orElse(0);
199+
200+
final DataFixerBuilder fixerBuilder = new DataFixerBuilder(new DataVersion(maxVersion));
196201
bootstrap.registerFixes(fixerBuilder);
197202

198203
return new SchemaValidator(null, schemaRegistry, fixerBuilder);
@@ -390,11 +395,11 @@ private ValidationResult validateFixCoverageInternal() {
390395
final int minVersion = schemas.stream()
391396
.map(s -> s.version().getVersion())
392397
.min(Comparator.naturalOrder())
393-
.orElse(0);
398+
.orElseThrow();
394399
final int maxVersion = schemas.stream()
395400
.map(s -> s.version().getVersion())
396401
.max(Comparator.naturalOrder())
397-
.orElse(0);
402+
.orElseThrow();
398403

399404
if (minVersion == maxVersion) {
400405
return ValidationResult.empty();

0 commit comments

Comments
 (0)