Skip to content

Commit 104f6b1

Browse files
authored
Fixes #1421: make JsonReadContext non-final (#1423)
1 parent 453696a commit 104f6b1

File tree

5 files changed

+56
-11
lines changed

5 files changed

+56
-11
lines changed

release-notes/CREDITS-2.x

+3
Original file line numberDiff line numberDiff line change
@@ -490,3 +490,6 @@ Fawzi Essam (@iifawzi)
490490
* Contributed fix for #1412: More cases of Non-blocking parser reporting incorrect locations
491491
when fed with non-zero offset
492492
(2.19.0)
493+
494+
Ilenia Salvadori (@isalvadori)
495+
* Requested #1421: Make `JsonReadContext` non-final

release-notes/VERSION-2.x

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ a pure JSON library.
3737
when fed with non-zero offset
3838
(reported by David N)
3939
(fixed by Fawzi E)
40+
#1421: Make `JsonReadContext` non-final
41+
(requested by Ilenia S)
42+
(fixed by @pjfanning)
4043

4144
2.18.3 (28-Feb-2025)
4245

src/main/java/com/fasterxml/jackson/core/json/JsonReadContext.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
* Extension of {@link JsonStreamContext}, which implements
88
* core methods needed, and also exposes
99
* more complete API to parser implementation classes.
10+
*<p>
11+
* NOTE: non-final since 2.19
1012
*/
11-
public final class JsonReadContext extends JsonStreamContext
13+
public class JsonReadContext extends JsonStreamContext
1214
{
1315
// // // Configuration
1416

src/test/java/com/fasterxml/jackson/core/json/JsonReadContextTest.java

+21-10
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import org.junit.jupiter.api.Test;
44

5-
import com.fasterxml.jackson.core.JUnit5TestBase;
6-
import com.fasterxml.jackson.core.JsonGenerator;
7-
import com.fasterxml.jackson.core.JsonParseException;
5+
import com.fasterxml.jackson.core.*;
86
import com.fasterxml.jackson.core.io.ContentReference;
97

108
import static org.junit.jupiter.api.Assertions.*;
@@ -14,9 +12,16 @@
1412
*/
1513
class JsonReadContextTest extends JUnit5TestBase
1614
{
15+
static class MyContext extends JsonReadContext {
16+
public MyContext(JsonReadContext parent, int nestingDepth, DupDetector dups,
17+
int type, int lineNr, int colNr) {
18+
super(parent, nestingDepth, dups, type, lineNr, colNr);
19+
}
20+
}
21+
1722
@Test
1823
void setCurrentNameTwiceWithSameNameRaisesJsonParseException() throws Exception
19-
{
24+
{
2025
DupDetector dupDetector = DupDetector.rootDetector((JsonGenerator) null);
2126
JsonReadContext jsonReadContext = new JsonReadContext((JsonReadContext) null, 0,
2227
dupDetector, 2441, 2441, 2441);
@@ -27,21 +32,21 @@ void setCurrentNameTwiceWithSameNameRaisesJsonParseException() throws Exception
2732
} catch (JsonParseException e) {
2833
verifyException(e, "Duplicate field 'dupField'");
2934
}
30-
}
35+
}
3136

3237
@Test
3338
void setCurrentName() throws Exception
34-
{
39+
{
3540
JsonReadContext jsonReadContext = JsonReadContext.createRootContext(0, 0, (DupDetector) null);
3641
jsonReadContext.setCurrentName("abc");
3742
assertEquals("abc", jsonReadContext.getCurrentName());
3843
jsonReadContext.setCurrentName(null);
3944
assertNull(jsonReadContext.getCurrentName());
40-
}
45+
}
4146

4247
@Test
4348
void reset()
44-
{
49+
{
4550
DupDetector dupDetector = DupDetector.rootDetector((JsonGenerator) null);
4651
JsonReadContext jsonReadContext = JsonReadContext.createRootContext(dupDetector);
4752
final ContentReference bogusSrc = ContentReference.unknown();
@@ -57,6 +62,12 @@ void reset()
5762
assertEquals("?", jsonReadContext.typeDesc());
5863
assertEquals(500, jsonReadContext.startLocation(bogusSrc).getLineNr());
5964
assertEquals(200, jsonReadContext.startLocation(bogusSrc).getColumnNr());
60-
}
65+
}
6166

62-
}
67+
// [core#1421]
68+
@Test
69+
void testExtension() {
70+
MyContext context = new MyContext(null, 0, null, 0, 0, 0);
71+
assertNotNull(context);
72+
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.fasterxml.jackson.core.json;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import com.fasterxml.jackson.core.*;
6+
7+
import static org.junit.jupiter.api.Assertions.*;
8+
9+
/**
10+
* Unit tests for class {@link JsonWriteContext}.
11+
*/
12+
public class JsonWriteContextTest extends JUnit5TestBase
13+
{
14+
static class MyContext extends JsonWriteContext {
15+
public MyContext(int type, JsonWriteContext parent, DupDetector dups, Object currValue) {
16+
super(type, parent, dups, currValue);
17+
}
18+
}
19+
20+
// [core#1421]
21+
@Test
22+
void testExtension() {
23+
MyContext context = new MyContext(0, null, null, 0);
24+
assertNotNull(context);
25+
}
26+
}

0 commit comments

Comments
 (0)