Skip to content

Commit

Permalink
Refactor exception generation by JsonParser (#1179)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Dec 28, 2023
1 parent 505126a commit 07b45ef
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 34 deletions.
35 changes: 18 additions & 17 deletions src/main/java/com/fasterxml/jackson/core/JsonParseException.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,9 @@ public class JsonParseException
{
private static final long serialVersionUID = 2L; // 2.7

@Deprecated // since 2.7
public JsonParseException(String msg, JsonLocation loc) {
super(msg, loc, null);
}

@Deprecated // since 2.7
public JsonParseException(String msg, JsonLocation loc, Throwable root) {
super(msg, loc, root);
// @since 2.15
public JsonParseException(String msg) {
this(null, msg, null, null);
}

/**
Expand All @@ -39,27 +34,33 @@ public JsonParseException(String msg, JsonLocation loc, Throwable root) {
* @since 2.7
*/
public JsonParseException(JsonParser p, String msg) {
super(p, msg);
this(p, msg, _currentLocation(p), null);
}

// @since 2.7
public JsonParseException(JsonParser p, String msg, Throwable root) {
super(p, msg, root);
public JsonParseException(JsonParser p, String msg, Throwable rootCause) {
this(p, msg, _currentLocation(p), rootCause);
}

// @since 2.7
public JsonParseException(JsonParser p, String msg, JsonLocation loc) {
super(p, msg, loc);
this(p, msg, loc, null);
}

// Canonical constructor
// @since 2.7
public JsonParseException(JsonParser p, String msg, JsonLocation loc, Throwable root) {
super(p, msg, loc, root);
public JsonParseException(JsonParser p, String msg, JsonLocation loc, Throwable rootCause) {
super(p, msg, loc, rootCause);
}

// @since 2.15
public JsonParseException(String msg) {
super(msg);
@Deprecated // since 2.7
public JsonParseException(String msg, JsonLocation loc) {
this(null, msg, loc, null);
}

@Deprecated // since 2.7
public JsonParseException(String msg, JsonLocation loc, Throwable rootCause) {
this(null, msg, loc, rootCause);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ protected final void _throwInternal() {
}

protected final JsonParseException _constructError(String msg, Throwable t) {
return new JsonParseException(this, msg, t);
return new JsonParseException(this, msg, currentLocation(), t);
}

@Deprecated // since 2.11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,35 @@ public abstract class StreamReadException
*/
protected RequestPayload _requestPayload;

// @since 2.15
protected StreamReadException(String msg) {
this(null, msg, null, null);
}

protected StreamReadException(JsonParser p, String msg) {
super(msg, (p == null) ? null : p.currentLocation());
_processor = p;
this(p, msg, _currentLocation(p), null);
}

protected StreamReadException(JsonParser p, String msg, Throwable root) {
super(msg, (p == null) ? null : p.currentLocation(), root);
_processor = p;
protected StreamReadException(JsonParser p, String msg, Throwable rootCause) {
this(p, msg, _currentLocation(p), rootCause);
}

protected StreamReadException(JsonParser p, String msg, JsonLocation loc) {
super(msg, loc, null);
_processor = p;
this(p, msg, loc, null);
}

protected StreamReadException(String msg, JsonLocation loc, Throwable rootCause) {
this(null, msg, loc, rootCause);
}

// Canonical constructor
// @since 2.13
protected StreamReadException(JsonParser p, String msg, JsonLocation loc,
Throwable rootCause) {
super(msg, loc, rootCause);
_processor = p;
}

protected StreamReadException(String msg, JsonLocation loc, Throwable rootCause) {
super(msg, loc, rootCause);
}

// @since 2.15
protected StreamReadException(String msg) {
super(msg);
}

/**
* Fluent method that may be used to assign originating {@link JsonParser},
* to be accessed using {@link #getProcessor()}.
Expand Down Expand Up @@ -117,4 +115,9 @@ public String getMessage() {
}
return msg;
}

// @since 2.17
protected static JsonLocation _currentLocation(JsonParser p) {
return (p == null) ? null : p.currentLocation();
}
}

0 comments on commit 07b45ef

Please sign in to comment.