Skip to content

Fix constant name lookup for null name prefix #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public Set<Object> getValuesForSuffix(String nameSuffix) {
* @throws ConstantException if the value wasn't found
*/
public String toCode(Object value, String namePrefix) throws ConstantException {
String prefixToUse = (namePrefix != null ? namePrefix.trim().toUpperCase(Locale.ENGLISH) : null);
String prefixToUse = (namePrefix != null ? namePrefix.trim().toUpperCase(Locale.ENGLISH) : "");
for (Map.Entry<String, Object> entry : this.fieldCache.entrySet()) {
if (entry.getKey().startsWith(prefixToUse) && entry.getValue().equals(value)) {
return entry.getKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,28 @@ public void testToCode() {
assertEquals(c.toCode(new Integer(0), "D"), "DOG");
assertEquals(c.toCode(new Integer(0), "DO"), "DOG");
assertEquals(c.toCode(new Integer(0), "DoG"), "DOG");
assertEquals(c.toCode(new Integer(0), null), "DOG");
assertEquals(c.toCode(new Integer(66), ""), "CAT");
assertEquals(c.toCode(new Integer(66), "C"), "CAT");
assertEquals(c.toCode(new Integer(66), "ca"), "CAT");
assertEquals(c.toCode(new Integer(66), "cAt"), "CAT");
assertEquals(c.toCode(new Integer(66), null), "CAT");
assertEquals(c.toCode("", ""), "S1");
assertEquals(c.toCode("", "s"), "S1");
assertEquals(c.toCode("", "s1"), "S1");
assertEquals(c.toCode("", null), "S1");
try {
c.toCode("bogus", "bogus");
fail("Should have thrown ConstantException");
}
catch (ConstantException expected) {
}
try {
c.toCode("bogus", null);
fail("Should have thrown ConstantException");
}
catch (ConstantException expected) {
}

assertEquals(c.toCodeForProperty(new Integer(1), "myProperty"), "MY_PROPERTY_NO");
assertEquals(c.toCodeForProperty(new Integer(2), "myProperty"), "MY_PROPERTY_YES");
Expand Down