Skip to content

Commit 07b45ef

Browse files
authored
Refactor exception generation by JsonParser (#1179)
1 parent 505126a commit 07b45ef

File tree

3 files changed

+38
-34
lines changed

3 files changed

+38
-34
lines changed

src/main/java/com/fasterxml/jackson/core/JsonParseException.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,9 @@ public class JsonParseException
1818
{
1919
private static final long serialVersionUID = 2L; // 2.7
2020

21-
@Deprecated // since 2.7
22-
public JsonParseException(String msg, JsonLocation loc) {
23-
super(msg, loc, null);
24-
}
25-
26-
@Deprecated // since 2.7
27-
public JsonParseException(String msg, JsonLocation loc, Throwable root) {
28-
super(msg, loc, root);
21+
// @since 2.15
22+
public JsonParseException(String msg) {
23+
this(null, msg, null, null);
2924
}
3025

3126
/**
@@ -39,27 +34,33 @@ public JsonParseException(String msg, JsonLocation loc, Throwable root) {
3934
* @since 2.7
4035
*/
4136
public JsonParseException(JsonParser p, String msg) {
42-
super(p, msg);
37+
this(p, msg, _currentLocation(p), null);
4338
}
4439

4540
// @since 2.7
46-
public JsonParseException(JsonParser p, String msg, Throwable root) {
47-
super(p, msg, root);
41+
public JsonParseException(JsonParser p, String msg, Throwable rootCause) {
42+
this(p, msg, _currentLocation(p), rootCause);
4843
}
4944

5045
// @since 2.7
5146
public JsonParseException(JsonParser p, String msg, JsonLocation loc) {
52-
super(p, msg, loc);
47+
this(p, msg, loc, null);
5348
}
5449

50+
// Canonical constructor
5551
// @since 2.7
56-
public JsonParseException(JsonParser p, String msg, JsonLocation loc, Throwable root) {
57-
super(p, msg, loc, root);
52+
public JsonParseException(JsonParser p, String msg, JsonLocation loc, Throwable rootCause) {
53+
super(p, msg, loc, rootCause);
5854
}
5955

60-
// @since 2.15
61-
public JsonParseException(String msg) {
62-
super(msg);
56+
@Deprecated // since 2.7
57+
public JsonParseException(String msg, JsonLocation loc) {
58+
this(null, msg, loc, null);
59+
}
60+
61+
@Deprecated // since 2.7
62+
public JsonParseException(String msg, JsonLocation loc, Throwable rootCause) {
63+
this(null, msg, loc, rootCause);
6364
}
6465

6566
/**

src/main/java/com/fasterxml/jackson/core/base/ParserMinimalBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ protected final void _throwInternal() {
774774
}
775775

776776
protected final JsonParseException _constructError(String msg, Throwable t) {
777-
return new JsonParseException(this, msg, t);
777+
return new JsonParseException(this, msg, currentLocation(), t);
778778
}
779779

780780
@Deprecated // since 2.11

src/main/java/com/fasterxml/jackson/core/exc/StreamReadException.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,35 @@ public abstract class StreamReadException
2626
*/
2727
protected RequestPayload _requestPayload;
2828

29+
// @since 2.15
30+
protected StreamReadException(String msg) {
31+
this(null, msg, null, null);
32+
}
33+
2934
protected StreamReadException(JsonParser p, String msg) {
30-
super(msg, (p == null) ? null : p.currentLocation());
31-
_processor = p;
35+
this(p, msg, _currentLocation(p), null);
3236
}
3337

34-
protected StreamReadException(JsonParser p, String msg, Throwable root) {
35-
super(msg, (p == null) ? null : p.currentLocation(), root);
36-
_processor = p;
38+
protected StreamReadException(JsonParser p, String msg, Throwable rootCause) {
39+
this(p, msg, _currentLocation(p), rootCause);
3740
}
3841

3942
protected StreamReadException(JsonParser p, String msg, JsonLocation loc) {
40-
super(msg, loc, null);
41-
_processor = p;
43+
this(p, msg, loc, null);
44+
}
45+
46+
protected StreamReadException(String msg, JsonLocation loc, Throwable rootCause) {
47+
this(null, msg, loc, rootCause);
4248
}
4349

50+
// Canonical constructor
4451
// @since 2.13
4552
protected StreamReadException(JsonParser p, String msg, JsonLocation loc,
4653
Throwable rootCause) {
4754
super(msg, loc, rootCause);
4855
_processor = p;
4956
}
5057

51-
protected StreamReadException(String msg, JsonLocation loc, Throwable rootCause) {
52-
super(msg, loc, rootCause);
53-
}
54-
55-
// @since 2.15
56-
protected StreamReadException(String msg) {
57-
super(msg);
58-
}
59-
6058
/**
6159
* Fluent method that may be used to assign originating {@link JsonParser},
6260
* to be accessed using {@link #getProcessor()}.
@@ -117,4 +115,9 @@ public String getMessage() {
117115
}
118116
return msg;
119117
}
118+
119+
// @since 2.17
120+
protected static JsonLocation _currentLocation(JsonParser p) {
121+
return (p == null) ? null : p.currentLocation();
122+
}
120123
}

0 commit comments

Comments
 (0)