Skip to content

Commit 11e33f9

Browse files
committed
And yet more refactoring for #668
1 parent 99b0025 commit 11e33f9

File tree

3 files changed

+60
-17
lines changed

3 files changed

+60
-17
lines changed

Diff for: src/main/java/tools/jackson/core/JacksonException.java

+53-2
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,65 @@ protected JacksonException(Throwable rootCause) {
187187
}
188188

189189
protected JacksonException(String msg, Throwable rootCause) {
190-
this(msg, null, rootCause);
190+
this(null, msg, null, rootCause);
191191
}
192192

193193
protected JacksonException(String msg, JsonLocation loc, Throwable rootCause) {
194+
this(null, msg, loc, rootCause);
195+
}
196+
197+
protected JacksonException(Closeable processor, Throwable rootCause) {
198+
super(rootCause);
199+
_processor = processor;
200+
_location = _nonNullLocation(null);
201+
}
202+
203+
protected JacksonException(Closeable processor, String msg, JsonLocation loc,
204+
Throwable rootCause) {
194205
super(msg, rootCause);
195-
_location = (loc == null) ? JsonLocation.NA : loc;
206+
_processor = processor;
207+
_location = _nonNullLocation(loc);
208+
}
209+
210+
protected JacksonException(Closeable processor, String msg)
211+
{
212+
super(msg);
213+
_processor = processor;
214+
JsonLocation loc = null;
215+
if (processor instanceof JsonParser) {
216+
// 17-Aug-2015, tatu: Use of token location makes some sense from databinding,
217+
// since actual parsing (current) location is typically only needed for low-level
218+
// parsing exceptions.
219+
// 10-Jun-2024, tatu: Used from streaming too, current location possibly better
220+
loc = ((JsonParser) processor).currentLocation();
221+
}
222+
_location = _nonNullLocation(loc);
196223
}
197224

225+
protected JacksonException(Closeable processor, String msg, Throwable problem)
226+
{
227+
super(msg, problem);
228+
_processor = processor;
229+
JsonLocation loc = null;
230+
if (problem instanceof JacksonException) {
231+
loc = ((JacksonException) problem).getLocation();
232+
} else if (processor instanceof JsonParser) {
233+
loc = ((JsonParser) processor).currentLocation();
234+
}
235+
_location = _nonNullLocation(loc);
236+
}
237+
238+
protected JacksonException(Closeable processor, String msg, JsonLocation loc)
239+
{
240+
super(msg);
241+
_processor = processor;
242+
_location = _nonNullLocation(loc);
243+
}
244+
245+
private static JsonLocation _nonNullLocation(JsonLocation loc) {
246+
return (loc == null) ? JsonLocation.NA : loc;
247+
}
248+
198249
// @since 3.0
199250
public JacksonException withCause(Throwable cause) {
200251
initCause(cause);

Diff for: src/main/java/tools/jackson/core/exc/StreamReadException.java

+4-9
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,23 @@ public class StreamReadException
1313

1414
public StreamReadException(String msg) {
1515
super(msg);
16-
_processor = null;
1716
}
1817

1918
public StreamReadException(JsonParser p, String msg) {
20-
super(msg, (p == null) ? null : p.currentLocation(), null);
21-
_processor = p;
19+
super(p, msg);
2220
}
2321

2422
public StreamReadException(JsonParser p, String msg, Throwable root) {
25-
super(msg, (p == null) ? null : p.currentLocation(), root);
26-
_processor = p;
23+
super(p, msg, root);
2724
}
2825

2926
public StreamReadException(JsonParser p, String msg, JsonLocation loc) {
30-
super(msg, loc, null);
31-
_processor = p;
27+
super(p, msg, loc);
3228
}
3329

3430
public StreamReadException(JsonParser p, String msg, JsonLocation loc,
3531
Throwable rootCause) {
36-
super(msg, loc, rootCause);
37-
_processor = p;
32+
super(p, msg, loc, rootCause);
3833
}
3934

4035
/**

Diff for: src/main/java/tools/jackson/core/exc/StreamWriteException.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,15 @@ public class StreamWriteException
1212
private final static long serialVersionUID = 3L;
1313

1414
public StreamWriteException(JsonGenerator g, Throwable rootCause) {
15-
super(rootCause);
16-
_processor = g;
15+
super(g, rootCause);
1716
}
1817

1918
public StreamWriteException(JsonGenerator g, String msg) {
20-
super(msg);
21-
_processor = g;
19+
super(g, msg);
2220
}
2321

2422
public StreamWriteException(JsonGenerator g, String msg, Throwable rootCause) {
25-
super(msg, null, rootCause);
26-
_processor = g;
23+
super(g, msg, rootCause);
2724
}
2825

2926
/**

0 commit comments

Comments
 (0)