Skip to content

Commit d69d5e2

Browse files
committed
explain position information numbers in syntax exception
1 parent f1c9d07 commit d69d5e2

10 files changed

+90
-90
lines changed

src/main/java/org/json/JSONTokener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,11 +520,11 @@ public JSONException syntaxError(String message, Throwable causedBy) {
520520
/**
521521
* Make a printable string of this JSONTokener.
522522
*
523-
* @return " at {index} [character {character} line {line}]"
523+
* @return " at index {index} [character number {character} in line {line}]"
524524
*/
525525
@Override
526526
public String toString() {
527-
return " at " + this.index + " [character " + this.character + " line " +
527+
return " at index " + this.index + " [character number " + this.character + " in line " +
528528
this.line + "]";
529529
}
530530

src/test/java/org/json/junit/CDLTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void unbalancedQuoteInName() {
6666
fail("Expecting an exception");
6767
} catch (JSONException e) {
6868
assertEquals("Expecting an exception message",
69-
"Missing close quote '\"'. at 12 [character 0 line 2]",
69+
"Missing close quote '\"'. at index 12 [character number 0 in line 2]",
7070
e.getMessage());
7171
}
7272
}
@@ -83,7 +83,7 @@ public void unbalancedQuoteInValue() {
8383
fail("Expecting an exception");
8484
} catch (JSONException e) {
8585
assertEquals("Expecting an exception message",
86-
"Missing close quote '\"'. at 22 [character 11 line 2]",
86+
"Missing close quote '\"'. at index 22 [character number 11 in line 2]",
8787
e.getMessage());
8888

8989
}
@@ -101,7 +101,7 @@ public void nullInName() {
101101
fail("Expecting an exception");
102102
} catch (JSONException e) {
103103
assertEquals("Expecting an exception message",
104-
"Bad character 'o' (111). at 2 [character 3 line 1]",
104+
"Bad character 'o' (111). at index 2 [character number 3 in line 1]",
105105
e.getMessage());
106106

107107
}
@@ -119,7 +119,7 @@ public void unbalancedEscapedQuote(){
119119
fail("Expecting an exception");
120120
} catch (JSONException e) {
121121
assertEquals("Expecting an exception message",
122-
"Missing close quote '\"'. at 26 [character 15 line 2]",
122+
"Missing close quote '\"'. at index 26 [character number 15 in line 2]",
123123
e.getMessage());
124124

125125
}
@@ -170,7 +170,7 @@ public void badEscapedQuote(){
170170
} catch (JSONException e) {
171171
//System.out.println("Message" + e.getMessage());
172172
assertEquals("Expecting an exception message",
173-
"Bad character 'V' (86). at 20 [character 9 line 2]",
173+
"Bad character 'V' (86). at index 20 [character number 9 in line 2]",
174174
e.getMessage());
175175

176176
}

src/test/java/org/json/junit/CookieListTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void malFormedCookieListException() {
5757
* Not sure of the missing char, but full string compare fails
5858
*/
5959
assertEquals("Expecting an exception message",
60-
"Expected '=' and instead saw '' at 25 [character 26 line 1]",
60+
"Expected '=' and instead saw '' at index 25 [character number 26 in line 1]",
6161
e.getMessage());
6262
}
6363
}

src/test/java/org/json/junit/CookieTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void malFormedNameValueException() {
4848
fail("Expecting an exception");
4949
} catch (JSONException e) {
5050
assertEquals("Expecting an exception message",
51-
"Expected '=' and instead saw '' at 25 [character 26 line 1]",
51+
"Expected '=' and instead saw '' at index 25 [character number 26 in line 1]",
5252
e.getMessage());
5353
}
5454
}

src/test/java/org/json/junit/JSONArrayTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public void emptyStr() {
127127
assertNull("Should throw an exception", new JSONArray(str));
128128
} catch (JSONException e) {
129129
assertEquals("Expected an exception message",
130-
"A JSONArray text must start with '[' at 0 [character 1 line 1]",
130+
"A JSONArray text must start with '[' at index 0 [character number 1 in line 1]",
131131
e.getMessage());
132132
}
133133
}
@@ -142,7 +142,7 @@ public void unclosedArray() {
142142
assertNull("Should throw an exception", new JSONArray("["));
143143
} catch (JSONException e) {
144144
assertEquals("Expected an exception message",
145-
"Expected a ',' or ']' at 1 [character 2 line 1]",
145+
"Expected a ',' or ']' at index 1 [character number 2 in line 1]",
146146
e.getMessage());
147147
}
148148
}
@@ -157,7 +157,7 @@ public void unclosedArray2() {
157157
assertNull("Should throw an exception", new JSONArray("[\"test\""));
158158
} catch (JSONException e) {
159159
assertEquals("Expected an exception message",
160-
"Expected a ',' or ']' at 7 [character 8 line 1]",
160+
"Expected a ',' or ']' at index 7 [character number 8 in line 1]",
161161
e.getMessage());
162162
}
163163
}
@@ -172,7 +172,7 @@ public void unclosedArray3() {
172172
assertNull("Should throw an exception", new JSONArray("[\"test\","));
173173
} catch (JSONException e) {
174174
assertEquals("Expected an exception message",
175-
"Expected a ',' or ']' at 8 [character 9 line 1]",
175+
"Expected a ',' or ']' at index 8 [character number 9 in line 1]",
176176
e.getMessage());
177177
}
178178
}

src/test/java/org/json/junit/JSONMLTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void emptyXMLException() {
4949
fail("Expecting an exception");
5050
} catch (JSONException e) {
5151
assertEquals("Expecting an exception message",
52-
"Bad XML at 0 [character 1 line 1]",
52+
"Bad XML at index 0 [character number 1 in line 1]",
5353
e.getMessage());
5454
}
5555
}
@@ -102,7 +102,7 @@ public void nonXMLException() {
102102
fail("Expecting an exception");
103103
} catch (JSONException e) {
104104
assertEquals("Expecting an exception message",
105-
"Bad XML at 23 [character 24 line 1]",
105+
"Bad XML at index 23 [character number 24 in line 1]",
106106
e.getMessage());
107107
}
108108
}
@@ -205,7 +205,7 @@ public void invalidSlashInTagException() {
205205
fail("Expecting an exception");
206206
} catch (JSONException e) {
207207
assertEquals("Expecting an exception message",
208-
"Misshaped tag at 176 [character 14 line 4]",
208+
"Misshaped tag at index 176 [character number 14 in line 4]",
209209
e.getMessage());
210210
}
211211
}
@@ -230,7 +230,7 @@ public void invalidBangInTagException() {
230230
fail("Expecting an exception");
231231
} catch (JSONException e) {
232232
assertEquals("Expecting an exception message",
233-
"Misshaped meta tag at 215 [character 12 line 7]",
233+
"Misshaped meta tag at index 215 [character number 12 in line 7]",
234234
e.getMessage());
235235
}
236236
}
@@ -260,7 +260,7 @@ public void invalidBangNoCloseInTagException() {
260260
fail("Expecting an exception");
261261
} catch (JSONException e) {
262262
assertEquals("Expecting an exception message",
263-
"Misshaped meta tag at 214 [character 12 line 7]",
263+
"Misshaped meta tag at index 214 [character number 12 in line 7]",
264264
e.getMessage());
265265
}
266266
}
@@ -290,7 +290,7 @@ public void noCloseStartTagException() {
290290
fail("Expecting an exception");
291291
} catch (JSONException e) {
292292
assertEquals("Expecting an exception message",
293-
"Misplaced '<' at 194 [character 5 line 6]",
293+
"Misplaced '<' at index 194 [character number 5 in line 6]",
294294
e.getMessage());
295295
}
296296
}
@@ -350,7 +350,7 @@ public void noCloseEndBraceException() {
350350
fail("Expecting an exception");
351351
} catch (JSONException e) {
352352
assertEquals("Expecting an exception message",
353-
"Misplaced '<' at 206 [character 1 line 7]",
353+
"Misplaced '<' at index 206 [character number 1 in line 7]",
354354
e.getMessage());
355355
}
356356
}
@@ -380,7 +380,7 @@ public void invalidCDATABangInTagException() {
380380
fail("Expecting an exception");
381381
} catch (JSONException e) {
382382
assertEquals("Expecting an exception message",
383-
"Expected 'CDATA[' at 204 [character 11 line 5]",
383+
"Expected 'CDATA[' at index 204 [character number 11 in line 5]",
384384
e.getMessage());
385385
}
386386
}
@@ -682,7 +682,7 @@ public void commentsInXML() {
682682
"<address>\n"+
683683
"<!-- <!--[CDATA[ this is -- <another> comment ]] -->\n"+
684684
"<name>Joe Tester</name>\n"+
685-
"<!-- this is a - multi line \n"+
685+
"<!-- this is a - multi in line \n"+
686686
"comment -->\n"+
687687
"<street>Baker street 5</street>\n"+
688688
"</address>\n"+
@@ -815,7 +815,7 @@ public void testIssue484InfinteLoop1() {
815815
fail("Exception expected for invalid JSON.");
816816
} catch (JSONException ex) {
817817
assertEquals("Exception string did not match: ",
818-
"Unterminated string at 271 [character 272 line 1]",
818+
"Unterminated string at index 271 [character number 272 in line 1]",
819819
ex.getMessage());
820820
}
821821
}
@@ -829,7 +829,7 @@ public void testIssue484InfinteLoop2() {
829829
fail("Exception expected for invalid JSON.");
830830
} catch (JSONException ex) {
831831
assertEquals("Exception string did not match: ",
832-
"Unterminated string at 242 [character 238 line 2]",
832+
"Unterminated string at index 242 [character number 238 in line 2]",
833833
ex.getMessage());
834834
}
835835
}

0 commit comments

Comments
 (0)