Skip to content

Commit

Permalink
And yet more refactoring for #668 (#1302)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jun 11, 2024
1 parent 99b0025 commit 321b703
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 20 deletions.
58 changes: 55 additions & 3 deletions src/main/java/tools/jackson/core/JacksonException.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ Object writeReplace() {
* NOTE: typically not serializable hence <code>transient</code>
*/
protected transient Closeable _processor;

/*
/**********************************************************************
/* Life-cycle
Expand All @@ -187,14 +187,66 @@ protected JacksonException(Throwable rootCause) {
}

protected JacksonException(String msg, Throwable rootCause) {
this(msg, null, rootCause);
this(null, msg, null, rootCause);
}

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

protected JacksonException(Closeable processor, Throwable rootCause) {
super(rootCause);
_processor = processor;
_location = _nonNullLocation(null);
}

protected JacksonException(Closeable processor, String msg, JsonLocation loc,
Throwable rootCause) {
super(msg, rootCause);
_location = (loc == null) ? JsonLocation.NA : loc;
_processor = processor;
_location = _nonNullLocation(loc);
}

protected JacksonException(Closeable processor, String msg)
{
super(msg);
_processor = processor;
JsonLocation loc = null;
if (processor instanceof JsonParser) {
// 17-Aug-2015, tatu: Use of token location makes some sense from databinding,
// since actual parsing (current) location is typically only needed for low-level
// parsing exceptions.
// 10-Jun-2024, tatu: Used from streaming too, so not 100% sure. But won't change yet
loc = ((JsonParser) processor).currentTokenLocation();
}
_location = _nonNullLocation(loc);
}

protected JacksonException(Closeable processor, String msg, Throwable problem)
{
super(msg, problem);
_processor = processor;
JsonLocation loc = null;
if (problem instanceof JacksonException) {
loc = ((JacksonException) problem).getLocation();
} else if (processor instanceof JsonParser) {
// 10-Jun-2024, tatu: Current vs token location?
loc = ((JsonParser) processor).currentTokenLocation();
}
_location = _nonNullLocation(loc);
}

protected JacksonException(Closeable processor, String msg, JsonLocation loc)
{
super(msg);
_processor = processor;
_location = _nonNullLocation(loc);
}

private static JsonLocation _nonNullLocation(JsonLocation loc) {
return (loc == null) ? JsonLocation.NA : loc;
}

// @since 3.0
public JacksonException withCause(Throwable cause) {
initCause(cause);
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/tools/jackson/core/exc/StreamReadException.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,27 @@ public class StreamReadException

public StreamReadException(String msg) {
super(msg);
_processor = null;
}

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

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

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

public StreamReadException(JsonParser p, String msg, JsonLocation loc,
Throwable rootCause) {
super(msg, loc, rootCause);
_processor = p;
super(p, msg, loc, rootCause);
}

private static JsonLocation _loc(JsonParser p) {
return(p == null) ? null : p.currentLocation();
}

/**
Expand All @@ -52,6 +51,7 @@ public StreamReadException withParser(JsonParser p) {
return this;
}

// Overridden for co-variance
@Override
public JsonParser processor() {
return (JsonParser) _processor;
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/tools/jackson/core/exc/StreamWriteException.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@ public class StreamWriteException
private final static long serialVersionUID = 3L;

public StreamWriteException(JsonGenerator g, Throwable rootCause) {
super(rootCause);
_processor = g;
super(g, rootCause);
}

public StreamWriteException(JsonGenerator g, String msg) {
super(msg);
_processor = g;
super(g, msg);
}

public StreamWriteException(JsonGenerator g, String msg, Throwable rootCause) {
super(msg, null, rootCause);
_processor = g;
super(g, msg, rootCause);
}

/**
Expand All @@ -39,6 +36,9 @@ public StreamWriteException withGenerator(JsonGenerator g) {
return this;
}

// Overridden for co-variance
@Override
public JsonGenerator processor() { return (JsonGenerator) _processor; }
public JsonGenerator processor() {
return (JsonGenerator) _processor;
}
}

0 comments on commit 321b703

Please sign in to comment.