Skip to content

Commit

Permalink
feat(objectionary#757): add safe checks to the method properties parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Oct 14, 2024
1 parent 3806d81 commit 40533a4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* This exception is thrown when XMIR parsing fails.
* @since 0.6
*/
final class XmirParsingException extends IllegalStateException {
final class ParsingException extends IllegalStateException {

/**
* Serial version UID.
Expand All @@ -40,7 +40,7 @@ final class XmirParsingException extends IllegalStateException {
* @param message Message.
* @param cause Cause.
*/
XmirParsingException(final String message, final Throwable cause) {
ParsingException(final String message, final Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public BytecodeClass bytecode() {
this.properties().bytecode()
);
} catch (final IllegalStateException exception) {
throw new XmirParsingException(
throw new ParsingException(
String.format(
"Unexpected exception during parsing the class '%s'",
this.name()
Expand Down
28 changes: 19 additions & 9 deletions src/main/java/org/eolang/jeo/representation/xmir/XmlMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public BytecodeMethod bytecode() {
.orElse(new BytecodeMaxs(0, 0))
);
} catch (final IllegalStateException exception) {
throw new XmirParsingException(
throw new ParsingException(
String.format(
"Unexpected exception during parsing the method '%s'",
this.name()
Expand Down Expand Up @@ -183,14 +183,24 @@ private Optional<XmlMaxs> maxs() {
* @return Properties.
*/
private BytecodeMethodProperties properties() {
return new BytecodeMethodProperties(
this.access(),
this.name(),
this.descriptor(),
this.signature(),
this.params(),
this.exceptions()
);
try {
return new BytecodeMethodProperties(
this.access(),
this.name(),
this.descriptor(),
this.signature(),
this.params(),
this.exceptions()
);
} catch (final IllegalStateException exception) {
throw new ParsingException(
String.format(
"Unexpected exception during parsing the method '%s' properties",
this.name()
),
exception
);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public BytecodeProgram bytecode() {
try {
return new BytecodeProgram(this.pckg(), this.top().bytecode());
} catch (final IllegalStateException exception) {
throw new XmirParsingException(
throw new ParsingException(
String.format(
"Unexpected exception during parsing the program in package '%s'",
this.pckg()
Expand Down

0 comments on commit 40533a4

Please sign in to comment.