Skip to content

Commit

Permalink
Fix #1768
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 19, 2017
1 parent 78761f1 commit 798da68
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
21 changes: 10 additions & 11 deletions src/main/java/com/fasterxml/jackson/databind/type/TypeParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public TypeParser withFactory(TypeFactory f) {

public JavaType parse(String canonical) throws IllegalArgumentException
{
canonical = canonical.trim();
MyTokenizer tokens = new MyTokenizer(canonical);
MyTokenizer tokens = new MyTokenizer(canonical.trim());
JavaType type = parseType(tokens);
// must be end, now
if (tokens.hasMoreTokens()) {
Expand Down Expand Up @@ -90,19 +89,18 @@ protected Class<?> findClass(String className, MyTokenizer tokens)

protected IllegalArgumentException _problem(MyTokenizer tokens, String msg)
{
return new IllegalArgumentException("Failed to parse type '"+tokens.getAllInput()
+"' (remaining: '"+tokens.getRemainingInput()+"'): "+msg);
return new IllegalArgumentException(String.format("Failed to parse type '%s' (remaining: '%s'): %s",
tokens.getAllInput(), tokens.getRemainingInput(), msg));
}

final static class MyTokenizer
extends StringTokenizer
final static class MyTokenizer extends StringTokenizer
{
protected final String _input;

protected int _index;

protected String _pushbackToken;

public MyTokenizer(String str) {
super(str, "<,>", true);
_input = str;
Expand All @@ -121,18 +119,19 @@ public String nextToken() {
_pushbackToken = null;
} else {
token = super.nextToken();
_index += token.length();
token = token.trim();
}
_index += token.length();
return token;
}

public void pushBack(String token) {
_pushbackToken = token;
_index -= token.length();
// let's NOT change index for now, since token may have been trim()ed
}

public String getAllInput() { return _input; }
public String getUsedInput() { return _input.substring(0, _index); }
// public String getUsedInput() { return _input.substring(0, _index); }
public String getRemainingInput() { return _input.substring(_index); }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,20 @@ public void testCanonicalNames()
assertEquals("java.util.EnumMap<com.fasterxml.jackson.databind.type.TestTypeFactory$EnumForCanonical,java.lang.String>",
can);
assertEquals(t, tf.constructFromCanonical(can));

}

// [databind#1768]
@SuppressWarnings("serial")
public void testCanonicalWithSpaces()
{
TypeFactory tf = TypeFactory.defaultInstance();
Object objects = new TreeMap<Object, Object>() { }; // to get subtype
String reflectTypeName = objects.getClass().getGenericSuperclass().getTypeName();
JavaType t1 = tf.constructType(objects.getClass().getGenericSuperclass());
// This will throw an Exception if you don't remove all white spaces from the String.
JavaType t2 = tf.constructFromCanonical(reflectTypeName);
assertNotNull(t2);
assertEquals(t2, t1);
}

/*
Expand Down

0 comments on commit 798da68

Please sign in to comment.