Skip to content

Instantly share code, notes, and snippets.

@johnclaus
Created February 8, 2013 16:16
Show Gist options
  • Save johnclaus/4740034 to your computer and use it in GitHub Desktop.
Save johnclaus/4740034 to your computer and use it in GitHub Desktop.
Groovy bug discovered by a coworker last week.
#!/usr/bin/env groovy
/*
* Simple key/value hash store & retrieve inspired by actual data
*
* $ groovy -v
* Groovy Version: 2.1.0 JVM: 1.7.0_11 Vendor: Oracle Corporation OS: Mac OS X
*/
def h1 = [:]
term = "hello"
h1[term] = 1
h1.each {k,v -> println "key: [$k] with value: [$v]" }
/* *********************************************** */
try {
def h2 = [:]
term = "serialVersionUID" // Here's a key you should apparently never use
h2[term] = 2
h2.each {k,v -> println "key: [$k] with value: [$v]" }
} catch (Exception e) {
println "Seriously?! " + e
}
/* *********************************************** */
def h3 = [:]
term = "serialVersionUID"
h3.put(term, 3) // At least this syntax doesn't Chernobyl
h3.each {k,v -> println "key: [$k] with value: [$v]" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment