Bug 485055 - "declare @field" failing for "final String" fields (see also Bug 327141)
Summary: "declare @field" failing for "final String" fields (see also Bug 327141)
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.8.6   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 1.8.8   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-12-31 09:45 EST by Peter Brummer CLA
Modified: 2016-01-05 18:45 EST (History)
1 user (show)

See Also:


Attachments
error dialog "Interneal Compiler Error:.." (31.70 KB, application/pdf)
2015-12-31 09:45 EST, Peter Brummer CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Brummer CLA 2015-12-31 09:45:30 EST
Created attachment 258948 [details]
error dialog "Interneal Compiler Error:.."

public aspect AspectWithStringConstant {
/*
 *  Just compile this aspect in eclipse luna in an AspectJ project...
 *  then an error dialog box(see ErrorDialog.pdf atached) 
 *  "Interneal Compiler Error:.." with the following details will arise: 
 *   
      java.lang.ClassCastException
      at org.aspectj.apache.bcel.generic.FieldGen.setValue(FieldGen.java:142)
      at org.aspectj.apache.bcel.generic.FieldGen.<init>(FieldGen.java:115)
      at org.aspectj.weaver.bcel.BcelField.getField(BcelField.java:233)
      at org.aspectj.weaver.bcel.LazyClassGen.writeBack(LazyClassGen.java:522)
      at org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:697)
      at org.aspectj.weaver.bcel.Bc ...  error: ClassCastException thrown: org.aspectj.apache.bcel.classfile.ConstantString cannot be cast to org.aspectj.apache.bcel.classfile.ConstantObject
 *  
 *  In the "RESOLVED" "FIXED" Bug 327141 the exception was related to an 
 *  "static final int" field.
 *  For this case and for "long" and "double" final fields the Bug was 
 *  fixed by Andrew Clement.
 *    
 *  In our case here, for final fields of type String, the 
 *  "java.lang.ClassCastException" still occurs.
 *  
 *  My guess is, that there is a general issue with types which allow only to
 *  create immutable objects like the types int, long, double etc. 
 *  and of course String. 
 *   
 *  I couldn't find the piece of code which was fixed by Andrew, so I couldn't 
 *  check whether it is possible or not, but maybe it is reasonable to 
 *  re-engineer that fix in a bit more abstract fashion in order to make it 
 *  work for all fields of "immutable-forcing"-types.
 *    
 *  Remark: I run also few other tests with fields of non 
 *          "immutable-forcing"-type.
 *          There came no "java.lang.ClassCastException...". 
 *          So I assume the Bugis only left in the case the field 
 *          type is final String. 
 *   
 */
    declare @field : String AspectWithStringConstant.SOME_NAME : @Loggable;
    public final String SOME_NAME = "";
    @interface Loggable { }
    public static void main(String[] args) {
      System.out.println("success");
    }
      
}
Comment 1 Andrew Clement CLA 2016-01-05 18:45:40 EST
Fixed. I had to extend the if statement in the BCEL FieldGen code to handle the ConstantString class. Thanks for doing the digging to find that other bug, using that I very quickly found the old test cases and code to update.