Skip to content

Commit ac878d6

Browse files
committed
include the message in Tokens#Problem#toString
Required adding accessor for "what" for use in tests
1 parent b3ac8d0 commit ac878d6

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

config/src/main/java/com/typesafe/config/impl/Tokens.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ static private class Problem extends Token {
121121
this.cause = cause;
122122
}
123123

124+
String what() {
125+
return what;
126+
}
127+
124128
String message() {
125129
return message;
126130
}
@@ -139,6 +143,9 @@ public String toString() {
139143
sb.append('\'');
140144
sb.append(what);
141145
sb.append('\'');
146+
sb.append(" (");
147+
sb.append(message);
148+
sb.append(")");
142149
return sb.toString();
143150
}
144151

@@ -276,6 +283,14 @@ static boolean isProblem(Token token) {
276283
return token instanceof Problem;
277284
}
278285

286+
static String getProblemWhat(Token token) {
287+
if (token instanceof Problem) {
288+
return ((Problem) token).what();
289+
} else {
290+
throw new ConfigException.BugOrBroken("tried to get problem what from " + token);
291+
}
292+
}
293+
279294
static String getProblemMessage(Token token) {
280295
if (token instanceof Problem) {
281296
return ((Problem) token).message();

config/src/test/scala/com/typesafe/config/impl/TokenizerTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ class TokenizerTest extends TestUtils {
229229
val problem = tokenized(1)
230230
assertTrue("reserved char is a problem", Tokens.isProblem(problem))
231231
if (invalid == '+')
232-
assertEquals("'end of file'", problem.toString())
232+
assertEquals("end of file", Tokens.getProblemWhat(problem))
233233
else
234-
assertEquals("'" + invalid + "'", problem.toString())
234+
assertEquals("" + invalid, Tokens.getProblemWhat(problem))
235235
}
236236
}
237237
}

0 commit comments

Comments
 (0)