diff options
author | eli-fin <eyfinkel@gmail.com> | 2019-05-19 14:10:35 +0300 |
---|---|---|
committer | Andy Clement <aclement@pivotal.io> | 2020-07-22 13:24:59 -0700 |
commit | 5c82acb58e2d665a46529290ae85ae717cbf2bd3 (patch) | |
tree | 66b81f1da9e9c80515a3a4e6b237417bfdec5fea /weaver | |
parent | 1dc58988d1b1048b268bd3d9df870b16ddea8045 (diff) | |
download | aspectj-5c82acb58e2d665a46529290ae85ae717cbf2bd3.tar.gz aspectj-5c82acb58e2d665a46529290ae85ae717cbf2bd3.zip |
Fix serialVersionUID initialization for java9+
Move initialization of static final serialVersionUID field to clinit, since as of java9+, the runtime won't allow setting final fields outside clinit
Signed-off-by: Eli Finkel <eyfinkel@gmail.com>
Diffstat (limited to 'weaver')
-rw-r--r-- | weaver/src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java | 37 |
1 files changed, 13 insertions, 24 deletions
diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java b/weaver/src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java index 83189e1d4..57761bbdf 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java @@ -1018,7 +1018,15 @@ public final class LazyClassGen { NameMangler.AJC_PRE_CLINIT_NAME, Type.NO_ARGS, NO_STRINGS, this); ajcPreClinit.getBody().insert(InstructionConstants.RETURN); methodGens.add(ajcPreClinit); - getStaticInitializer().getBody().insert(Utility.createInvoke(fact, ajcPreClinit)); + InstructionList clinitBody = getStaticInitializer().getBody(); + clinitBody.insert(Utility.createInvoke(fact, ajcPreClinit)); + if (serialVersionUIDRequiresInitialization) { + InstructionList il = new InstructionList(); + il.append(InstructionFactory.PUSH(getConstantPool(), calculatedSerialVersionUID)); + il.append(getFactory().createFieldAccess(getClassName(), "serialVersionUID", BasicType.LONG, + Constants.PUTSTATIC)); + clinitBody.insert(il); + } return ajcPreClinit; } @@ -1204,31 +1212,12 @@ public final class LazyClassGen { // } private void addAjcInitializers() { - if (tjpFields.size() == 0 && !serialVersionUIDRequiresInitialization) { + if (tjpFields.size() == 0) { return; } - InstructionList[] il = null; - - if (tjpFields.size() > 0) { - il = initializeAllTjps(); - } - - if (serialVersionUIDRequiresInitialization) { - InstructionList[] ilSVUID = new InstructionList[1]; - ilSVUID[0] = new InstructionList(); - ilSVUID[0].append(InstructionFactory.PUSH(getConstantPool(), calculatedSerialVersionUID)); - ilSVUID[0].append(getFactory().createFieldAccess(getClassName(), "serialVersionUID", BasicType.LONG, - Constants.PUTSTATIC)); - if (il == null) { - il = ilSVUID; - } else { - InstructionList[] newIl = new InstructionList[il.length + ilSVUID.length]; - System.arraycopy(il, 0, newIl, 0, il.length); - System.arraycopy(ilSVUID, 0, newIl, il.length, ilSVUID.length); - il = newIl; - } - } - + + InstructionList[] il = initializeAllTjps(); + LazyMethodGen prevMethod; LazyMethodGen nextMethod = null; if (this.isInterface()) { // Cannot sneak stuff into another static method in an interface |