Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.VerifyError: Bad access to protected data

Tags:

groovy

I have the following Groovy file "test.groovy":

import groovy.transform.CompileStatic

@CompileStatic
class Test {
  final Set<String> HISTORY = [] as HashSet

  Set<String> getHistory() {
    return HISTORY.clone() as HashSet<String>
  }
}

Test test = new Test()
println test.history

Compiling it with Groovy 2.4.1 works fine, however, when I run "groovy test.class" I get the following error:

Caught: java.lang.VerifyError: 
(class: Test, method: getHistory signature:()Ljava/util/Set;) 
Bad access to protected data  
java.lang.VerifyError: 
(class: Test, method: getHistory 
signature: ()Ljava/util/Set;) 
Bad access to protected data
at test.run(test.groovy:12)

Any ideas what I am doing wrong here?

like image 287
Matthias Avatar asked Feb 22 '26 13:02

Matthias


1 Answers

This actually is a bug in Groovy. A ticket was filed: https://issues.apache.org/jira/browse/GROOVY-7325

Workaround in this case:

It works if you are using a final HashSet<String> and then cast the clone up. Since the getter overrides the property basically anyway (make it private if you wanna be sure), it should not harm the intention of the original code.

like image 158
2 revs, 2 users 89%cfrick Avatar answered Feb 27 '26 03:02

2 revs, 2 users 89%cfrick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!