google / gwtmockito

Better GWT unit testing
https://google.github.io/gwtmockito
Apache License 2.0
157 stars 50 forks source link

Fix javassist 3.26.0-GA #86

Closed csobrinho closed 4 years ago

csobrinho commented 4 years ago

So two things that are happening here: 1) clazz.getClassFile().setAccessFlags(clazz.getModifiers() & ~Modifier.FINAL) is invalid since the modifiers have different info/flags than the accessFlag and then this trips java/javassist.

For instance for a final enum class inside a static inner class:

0x4019 ctClass.getModifiers()
  ENUM, FINAL, STATIC, PUBLIC
0x4009 ctClass.getModifiers() & ~Modifiers.FINAL
  ENUM, FINAL, STATIC, PUBLIC

0x4031 ctClass.getClassFile().getAccessFlags()
  ENUM, FINAL, SYNCHRONIZED, PUBLIC
0x4021 ctClass.getClassFile().getAccessFlags() & ~Modifiers.FINAL
  ENUM, SYNCHRONIZED, PUBLIC
0x4021 ctClass.getClassFile().getAccessFlags() & ~AccessFlags.FINAL
  ENUM, SYNCHRONIZED, PUBLIC

This leaves us with 2).

2) We can't use clazz.setModifiers(clazz.getModifiers() & ~Modifiers.FINAL) because it will try to update the inner classes of the class and this might trigger an exception if an inner CtClass was already loaded and frozen.

The reason it tries to update the inner classes is because it detects that the STATIC flag might have changed and this needs to be propagated to all inner classes, even if no change was needed!