Skip to content

Commit

Permalink
Make MappingWriter#create return null instead of throwing an exception
Browse files Browse the repository at this point in the history
  • Loading branch information
NebelNidas committed Oct 10, 2023
1 parent cee81f7 commit b4e5320
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/java/net/fabricmc/mappingio/MappingWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,19 @@
import net.fabricmc.mappingio.format.tiny.Tiny2FileWriter;

public interface MappingWriter extends Closeable, MappingVisitor {
@Nullable
static MappingWriter create(Path file, MappingFormat format) throws IOException {
if (format.hasSingleFile()) {
return create(Files.newBufferedWriter(file), format);
} else {
switch (format) {
case ENIGMA_DIR: return new EnigmaDirWriter(file, true);
default: throw new UnsupportedOperationException("format "+format+" is not implemented");
default: return null;
}
}
}

@Nullable
static MappingWriter create(Writer writer, MappingFormat format) throws IOException {
if (!format.hasSingleFile()) throw new IllegalArgumentException("format "+format+" is not applicable to a single writer");

Expand All @@ -49,7 +51,7 @@ static MappingWriter create(Writer writer, MappingFormat format) throws IOExcept
case TINY_2_FILE: return new Tiny2FileWriter(writer, false);
case ENIGMA_FILE: return new EnigmaFileWriter(writer);
case PROGUARD_FILE: return new ProGuardFileWriter(writer);
default: throw new UnsupportedOperationException("format "+format+" is not implemented");
default: return null;
}
}

Expand Down

0 comments on commit b4e5320

Please sign in to comment.