Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix for GROOVY-5247 #12

Closed
wants to merge 1 commit into from

2 participants

@jwagenleitner

Fixes issue introduced by GROOVY-5162 (commit c5456c8) that causes a NPE when checking for null keys on certain Map implementations (i.e., TreeMap, Hashtable).

@jwagenleitner jwagenleitner GROOVY-5247: fixes issue introduced by GROOVY-5162 that caused a NPE …
…when checking for null keys on certain Map implementations (i.e., TreeMap, Hashtable).
4dcaec8
@glaforge
Owner

Thanks for the fix!

@glaforge glaforge closed this
@melix melix referenced this pull request from a commit in melix/groovy-core
@roranade roranade Minor formatting fix for the properties mentioned in the section on G…
…rape (closes #12)
a75b51b
@melix melix referenced this pull request from a commit in melix/groovy-core
@roranade roranade Minor formatting fix for the properties mentioned in the section on G…
…rape (closes #12)
a19c513
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 12, 2012
  1. @jwagenleitner

    GROOVY-5247: fixes issue introduced by GROOVY-5162 that caused a NPE …

    jwagenleitner authored
    …when checking for null keys on certain Map implementations (i.e., TreeMap, Hashtable).
This page is out of date. Refresh to see the latest.
View
10 src/main/groovy/json/JsonOutput.groovy
@@ -139,10 +139,12 @@ class JsonOutput {
* @return a JSON object representation for a map
*/
static String toJson(Map m) {
- if(m.containsKey(null)) {
- throw new IllegalArgumentException('Null key for a Map not allowed')
- }
- "{" + m.collect { k, v -> toJson(k.toString()) + ':' + toJson(v) }.join(',') + "}"
+ "{" + m.collect { k, v ->
+ if (k == null) {
+ throw new IllegalArgumentException('Null key for a Map not allowed')
+ }
+ toJson(k.toString()) + ':' + toJson(v)
+ }.join(',') + "}"
}
/**
View
6 src/test/groovy/json/JsonOutputTest.groovy
@@ -287,6 +287,12 @@ class JsonOutputTest extends GroovyTestCase {
toJson([(null): 1])
}
}
+
+ void testGROOVY5247() {
+ def m = new TreeMap()
+ m.a = 1
+ assert toJson(m) == '{"a":1}'
+ }
}
@Canonical
Something went wrong with that request. Please try again.