Skip to content

Commit

Permalink
Java: throw a more appropriate exception. (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
overcat authored Jul 10, 2024
1 parent bdf833d commit ffe4ba5
Show file tree
Hide file tree
Showing 18 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/xdrgen/generators/java.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def render_enum(enum, out)
end
out.puts <<-EOS.strip_heredoc
default:
throw new RuntimeException("Unknown enum value: " + value);
throw new IllegalArgumentException("Unknown enum value: " + value);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/xdrgen/generators/java/XdrString.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class XdrString implements XdrElement {
public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
int size = stream.readInt();
if (size > maxSize) {
throw new InvalidClassException("String length " + size + " exceeds max size " + maxSize);
throw new IllegalArgumentException("String length " + size + " exceeds max size " + maxSize);
}
byte[] bytes = new byte[size];
stream.read(bytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static AccountFlags decode(XdrDataInputStream stream) throws IOException
switch (value) {
case 1: return AUTH_REQUIRED_FLAG;
default:
throw new RuntimeException("Unknown enum value: " + value);
throw new IllegalArgumentException("Unknown enum value: " + value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void encode(XdrDataOutputStream stream) throws IOException {
public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
int size = stream.readInt();
if (size > maxSize) {
throw new InvalidClassException("String length " + size + " exceeds max size " + maxSize);
throw new IllegalArgumentException("String length " + size + " exceeds max size " + maxSize);
}
byte[] bytes = new byte[size];
stream.read(bytes);
Expand Down
2 changes: 1 addition & 1 deletion spec/output/generator_spec_java/const.x/XdrString.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void encode(XdrDataOutputStream stream) throws IOException {
public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
int size = stream.readInt();
if (size > maxSize) {
throw new InvalidClassException("String length " + size + " exceeds max size " + maxSize);
throw new IllegalArgumentException("String length " + size + " exceeds max size " + maxSize);
}
byte[] bytes = new byte[size];
stream.read(bytes);
Expand Down
2 changes: 1 addition & 1 deletion spec/output/generator_spec_java/enum.x/Color.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static Color decode(XdrDataInputStream stream) throws IOException {
case 1: return GREEN;
case 2: return BLUE;
default:
throw new RuntimeException("Unknown enum value: " + value);
throw new IllegalArgumentException("Unknown enum value: " + value);
}
}

Expand Down
2 changes: 1 addition & 1 deletion spec/output/generator_spec_java/enum.x/Color2.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static Color2 decode(XdrDataInputStream stream) throws IOException {
case 1: return GREEN2;
case 2: return BLUE2;
default:
throw new RuntimeException("Unknown enum value: " + value);
throw new IllegalArgumentException("Unknown enum value: " + value);
}
}

Expand Down
2 changes: 1 addition & 1 deletion spec/output/generator_spec_java/enum.x/MessageType.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static MessageType decode(XdrDataInputStream stream) throws IOException {
case 12: return FBA_QUORUMSET;
case 13: return FBA_MESSAGE;
default:
throw new RuntimeException("Unknown enum value: " + value);
throw new IllegalArgumentException("Unknown enum value: " + value);
}
}

Expand Down
2 changes: 1 addition & 1 deletion spec/output/generator_spec_java/enum.x/XdrString.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void encode(XdrDataOutputStream stream) throws IOException {
public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
int size = stream.readInt();
if (size > maxSize) {
throw new InvalidClassException("String length " + size + " exceeds max size " + maxSize);
throw new IllegalArgumentException("String length " + size + " exceeds max size " + maxSize);
}
byte[] bytes = new byte[size];
stream.read(bytes);
Expand Down
2 changes: 1 addition & 1 deletion spec/output/generator_spec_java/nesting.x/UnionKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static UnionKey decode(XdrDataInputStream stream) throws IOException {
case 2: return TWO;
case 3: return OFFER;
default:
throw new RuntimeException("Unknown enum value: " + value);
throw new IllegalArgumentException("Unknown enum value: " + value);
}
}

Expand Down
2 changes: 1 addition & 1 deletion spec/output/generator_spec_java/nesting.x/XdrString.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void encode(XdrDataOutputStream stream) throws IOException {
public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
int size = stream.readInt();
if (size > maxSize) {
throw new InvalidClassException("String length " + size + " exceeds max size " + maxSize);
throw new IllegalArgumentException("String length " + size + " exceeds max size " + maxSize);
}
byte[] bytes = new byte[size];
stream.read(bytes);
Expand Down
2 changes: 1 addition & 1 deletion spec/output/generator_spec_java/optional.x/XdrString.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void encode(XdrDataOutputStream stream) throws IOException {
public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
int size = stream.readInt();
if (size > maxSize) {
throw new InvalidClassException("String length " + size + " exceeds max size " + maxSize);
throw new IllegalArgumentException("String length " + size + " exceeds max size " + maxSize);
}
byte[] bytes = new byte[size];
stream.read(bytes);
Expand Down
2 changes: 1 addition & 1 deletion spec/output/generator_spec_java/struct.x/XdrString.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void encode(XdrDataOutputStream stream) throws IOException {
public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
int size = stream.readInt();
if (size > maxSize) {
throw new InvalidClassException("String length " + size + " exceeds max size " + maxSize);
throw new IllegalArgumentException("String length " + size + " exceeds max size " + maxSize);
}
byte[] bytes = new byte[size];
stream.read(bytes);
Expand Down
2 changes: 1 addition & 1 deletion spec/output/generator_spec_java/test.x/Color.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static Color decode(XdrDataInputStream stream) throws IOException {
case 5: return BLUE;
case 6: return GREEN;
default:
throw new RuntimeException("Unknown enum value: " + value);
throw new IllegalArgumentException("Unknown enum value: " + value);
}
}

Expand Down
2 changes: 1 addition & 1 deletion spec/output/generator_spec_java/test.x/Nester.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static NestedEnum decode(XdrDataInputStream stream) throws IOException {
case 0: return BLAH_1;
case 1: return BLAH_2;
default:
throw new RuntimeException("Unknown enum value: " + value);
throw new IllegalArgumentException("Unknown enum value: " + value);
}
}

Expand Down
2 changes: 1 addition & 1 deletion spec/output/generator_spec_java/test.x/XdrString.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void encode(XdrDataOutputStream stream) throws IOException {
public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
int size = stream.readInt();
if (size > maxSize) {
throw new InvalidClassException("String length " + size + " exceeds max size " + maxSize);
throw new IllegalArgumentException("String length " + size + " exceeds max size " + maxSize);
}
byte[] bytes = new byte[size];
stream.read(bytes);
Expand Down
2 changes: 1 addition & 1 deletion spec/output/generator_spec_java/union.x/UnionKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static UnionKey decode(XdrDataInputStream stream) throws IOException {
case 0: return ERROR;
case 1: return MULTI;
default:
throw new RuntimeException("Unknown enum value: " + value);
throw new IllegalArgumentException("Unknown enum value: " + value);
}
}

Expand Down
2 changes: 1 addition & 1 deletion spec/output/generator_spec_java/union.x/XdrString.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void encode(XdrDataOutputStream stream) throws IOException {
public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
int size = stream.readInt();
if (size > maxSize) {
throw new InvalidClassException("String length " + size + " exceeds max size " + maxSize);
throw new IllegalArgumentException("String length " + size + " exceeds max size " + maxSize);
}
byte[] bytes = new byte[size];
stream.read(bytes);
Expand Down

0 comments on commit ffe4ba5

Please sign in to comment.