Skip to content

Commit

Permalink
Fix type of exception thrown if YAMM parser was already closed.
Browse files Browse the repository at this point in the history
Added a message for this case.
  • Loading branch information
leadpony committed Apr 26, 2020
1 parent 4030afc commit cd0d322
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ protected final JsonObject getValueAsObject() {

/* provides parsing exceptions */

protected JsonException newJsonException(String message) {
return new JsonException(message);
}

protected JsonException newJsonException(String message, Exception e) {
return new JsonException(message, e);
}
Expand Down
4 changes: 4 additions & 0 deletions joy-core/src/main/java/org/leadpony/joy/core/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public static String thatIOErrorOccurredWhileParserWasClosing() {
return format("IOErrorOccurredWhileParserWasClosing");
}

public static String thatParserHasBeenAlreadyClosed() {
return format("ParserHasBeenAlreadyClosed");
}

/*
* Messages for JSON generator
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ NoMoreParserEventsWereFound=No more parser events.
IOErrorOccurredWhileParserWasReading=An I/O error occurred while the parser was reading.
IOErrorOccurredWhileParserWasClosing=An I/O error occurred while the parser was closing.

ParserHasBeenAlreadyClosed=The parser has been already closed.

#
# Messages for JsonGenerator
#
Expand Down
2 changes: 2 additions & 0 deletions joy-yaml/src/main/java/org/leadpony/joy/yaml/YamlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public Event next() {
this.nextYamlEvent = null;
this.eventType = state.processEvent(yamlEvent, this);
return this.eventType.toJsonEvent();
} else if (alreadyClosed) {
throw newJsonException(Message.thatParserHasBeenAlreadyClosed());
} else {
throw new NoSuchElementException(Message.thatNoMoreParserEventsWereFound());
}
Expand Down

0 comments on commit cd0d322

Please sign in to comment.