Bug 28974 - Compiler error when introducing a "final" field
Summary: Compiler error when introducing a "final" field
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Jim Hugunin CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-01-03 10:28 EST by Adrian Colyer CLA
Modified: 2003-01-14 14:30 EST (History)
0 users

See Also:


Attachments
Mini-project that reproduces the error (6.91 KB, application/octet-stream)
2003-01-03 10:31 EST, Adrian Colyer CLA
no flags Details
Smallest possible test that reproduces the problem (319 bytes, application/octet-stream)
2003-01-08 04:09 EST, Adrian Colyer CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Adrian Colyer CLA 2003-01-03 10:28:23 EST
The aspect below fails to compile with 1.1b2, producing the compilation error: 
--------------------
$ ajc com/ibm/amc/*.java com/ibm/amc/ejb/*.java
d:/eclipse/runtime-workspace-ajsamples/Mock EJBs/com/ibm/amc/DemoBeanEJB.java:1:
 Cannot assign a value to the final field com.ibm.amc.DemoBean.ajc$interField$co
m_ibm_amc$verbose

!! no source information available !!

1 error
---------------------------


package com.ibm.amc;

import com.ibm.amc.ejb.SessionBean;
/**
 * @author colyer
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */
public aspect DemoBeanEJB {

	declare parents: DemoBean implements SessionBean;
	
        // THIS NEXT LINE IS THE CULPRIT
	static final boolean DemoBean.verbose = true;
	
	private transient String DemoBean.ctx;
	
	public void DemoBean.ejbActivate( ) {
		if ( verbose ) {
			System.out.println( "ejbActivate Called" );	
		}	
	}
}


-------------------
Making the inter-type declaration non-final solves the problem...
Comment 1 Adrian Colyer CLA 2003-01-03 10:31:40 EST
Created attachment 2885 [details]
Mini-project that reproduces the error
Comment 2 Jim Hugunin CLA 2003-01-07 21:13:48 EST
This seems like it could be reduced to a much smaller minimal test case that
would be easier to add to our test suite.  Can you reproduce this with just 2 
classes an no external dependencies?
Comment 3 Adrian Colyer CLA 2003-01-08 04:09:50 EST
Created attachment 2918 [details]
Smallest possible test that reproduces the problem

:-). Yes, here's a 5-line program that reproduces the problem.
Thanks, Adrian.
Comment 4 Jim Hugunin CLA 2003-01-14 14:30:16 EST
fixed cvs tree, testcase in new/finalfield/*

The fix involved a minor change to 
org.aspectj.weaver.AjcMemberMaker.makePublic to makePublicNonFinal

This means that all introduced fields are always implemented with a non-final 
field in the target class.  The compiler's checking rules still operate on the 
inter-type declaration which remains final.  The test case was extended to 
ensure that this checking still works to signal errors when final fields are 
assigned to.