Skip to content

Commit

Permalink
More incremental refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 13, 2024
1 parent 6ad85b9 commit c6b5649
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
21 changes: 21 additions & 0 deletions src/main/java/com/fasterxml/jackson/core/JsonParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2610,4 +2610,25 @@ protected JsonParseException _constructReadException(String msg, Throwable t) {
}
return e;
}

/**
* Helper method for constructing {@link JsonParseException}
* based on current state of the parser, except for specified
* {@link JsonLocation} for problem location (which may not be
* the exact current location)
*
* @param msg Base exception message to construct exception with
* @param loc Error location to report
*
* @return Read exception (of type {@link JsonParseException}) constructed
*
* @since 2.13
*/
protected JsonParseException _constructReadException(String msg, JsonLocation loc) {
JsonParseException e = new JsonParseException(this, msg, loc);
if (_requestPayload != null) {
e = e.withRequestPayload(_requestPayload);
}
return e;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ protected void _reportInvalidEOF(String msg, JsonToken currToken) throws JsonPar
* @throws JsonParseException Exception that describes problem with number validity
*/
protected void reportInvalidNumber(String msg) throws JsonParseException {
_reportError("Invalid numeric value: "+msg);
throw _constructReadException("Invalid numeric value: "+msg);
}

protected void _reportMissingRootWS(int ch) throws JsonParseException {
Expand Down Expand Up @@ -682,7 +682,7 @@ protected void _reportUnexpectedChar(int ch, String comment) throws JsonParseExc
if (comment != null) {
msg += ": "+comment;
}
_reportError(msg);
throw _constructReadException(msg, currentLocation());
}

/**
Expand All @@ -698,8 +698,7 @@ protected <T> T _reportUnexpectedNumberChar(int ch, String comment) throws JsonP
if (comment != null) {
msg += ": "+comment;
}
_reportError(msg);
return null; // never gets here
throw _constructReadException(msg, currentLocation());
}

@Deprecated // @since 2.14
Expand All @@ -710,7 +709,7 @@ protected void reportUnexpectedNumberChar(int ch, String comment) throws JsonPar
protected void _throwInvalidSpace(int i) throws JsonParseException {
char c = (char) i;
String msg = "Illegal character ("+_getCharDesc(c)+"): only regular white space (\\r, \\n, \\t) is allowed between tokens";
_reportError(msg);
throw _constructReadException(msg);
}

/*
Expand All @@ -719,6 +718,10 @@ protected void _throwInvalidSpace(int i) throws JsonParseException {
/**********************************************************
*/

protected final JsonParseException _constructError(String msg, Throwable t) {
return _constructReadException(msg, t);
}

protected final static String _getCharDesc(int ch)
{
char c = (char) ch;
Expand All @@ -732,21 +735,17 @@ protected final static String _getCharDesc(int ch)
}

protected final void _reportError(String msg) throws JsonParseException {
throw _constructError(msg);
throw _constructReadException(msg);
}

// @since 2.9
protected final void _reportError(String msg, Object arg) throws JsonParseException {
throw _constructError(String.format(msg, arg));
throw _constructReadException(msg, arg);
}

// @since 2.9
protected final void _reportError(String msg, Object arg1, Object arg2) throws JsonParseException {
throw _constructError(String.format(msg, arg1, arg2));
}

protected final void _wrapError(String msg, Throwable t) throws JsonParseException {
throw _constructError(msg, t);
throw _constructReadException(msg, arg1, arg2);
}

protected final void _throwInternal() {
Expand All @@ -758,8 +757,8 @@ protected final <T> T _throwInternalReturnAny() {
return VersionUtil.throwInternalReturnAny();
}

protected final JsonParseException _constructError(String msg, Throwable t) {
return new JsonParseException(this, msg, currentLocation(), t);
protected final void _wrapError(String msg, Throwable t) throws JsonParseException {
throw _constructReadException(msg, t);
}

@Deprecated // since 2.11
Expand Down

0 comments on commit c6b5649

Please sign in to comment.