Bug 149419

Summary: Default access field injection fails
Product: [Tools] AspectJ Reporter: Venkatesh Prasad Ranganath <rvprasad>
Component: CompilerAssignee: aspectj inbox <aspectj-inbox>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3    
Version: 1.5.2   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Venkatesh Prasad Ranganath CLA 2006-07-02 18:23:54 EDT
I'm executing the following snippet via AJDT based on 1.5.2 aspectj compiler.

When compiled and executed, the target program functions well with the below given aspect.  

As FA and AbstractFGNode are in the same package, using default access for "nodeCount" should suffice.  So, I removed the "public" modifier from the "CAUSE" statement.  The compilation succeeded but the execution failed at "EFFECT" statement with the following exception.  Unless my reasoning about access modifiers is incorrect, field injection and access should work.  I am suspecting this is a bug in the compiler.

Aspect
------

package edu.ksu.cis.indus.staticanalyses.flow;

import edu.ksu.cis.indus.staticanalyses.flow.FA;
import edu.ksu.cis.indus.staticanalyses.flow.AbstractFGNode;

public final aspect ProfilingAspect {

	public static int AbstractFGNode.nodeCount = 0;  // CAUSE

	private pointcut excludingAspect() : !within(ProfilingAspect);

	private pointcut nodeCreation() : initialization(AbstractFGNode.new(..));

	after() : nodeCreation() {
		AbstractFGNode.nodeCount++;
	};
	
	private pointcut FAanalyze() : (call(void FA.analyze(..))) && excludingAspect();

	void around() : FAanalyze() {
		proceed();
		System.out.println(AbstractFGNode.nodeCount + " number of nodes were created."); // EFFECT
	};
}



Exception
---------
Caused by: java.lang.NoSuchFieldError: nodeCount
        at edu.ksu.cis.indus.staticanalyses.flow.ProfilingAspect.ajc$inlineAccessFieldGet$edu_ksu_cis_indus_staticanalyses_flow_ProfilingAspect$edu_ksu_cis_indus_staticanalyses_flow_AbstractFGNode$nodeCount(ProfilingAspect.aj:1)
        at edu.ksu.cis.indus.staticanalyses.flow.ProfilingAspect.ajc$around$edu_ksu_cis_indus_staticanalyses_flow_ProfilingAspect$2$5847d8f2(ProfilingAspect.aj:32)
        at edu.ksu.cis.indus.staticanalyses.flow.AbstractAnalyzer.analyze(AbstractAnalyzer.java:111)
        at edu.ksu.cis.indus.staticanalyses.dependency.DependencyXMLizerCLI.analyze_aroundBody0(DependencyXMLizerCLI.java:424)
Comment 1 Andrew Clement CLA 2006-07-04 05:40:07 EDT
I am trying to recreate this but I dont seem to be able to.  Are you able to give me a cut down variant of the ITD'd class?

this works fine for me:
---8<----------
package a.b.c;


public final aspect ProfilingAspect {

  static int AbstractFGNode.nodeCount = 0;  // CAUSE

  private pointcut excludingAspect() : !within(ProfilingAspect);

  private pointcut nodeCreation() : initialization(AbstractFGNode.new(..));

  after() : nodeCreation() {
    AbstractFGNode.nodeCount++;
  };

  public static void m() {
    System.out.println(AbstractFGNode.nodeCount + 
      " number of nodes were created."); // EFFECT
  }

  public static void main(String[] argv) {
    new Foo();
    m();
  }
}

abstract class AbstractFGNode {}

class Foo extends AbstractFGNode {}
---8<----------
Comment 2 Venkatesh Prasad Ranganath CLA 2006-07-06 23:15:26 EDT
If it would be easier, then you can the actual ITD'd classes available in binary form (in jar files) from the Indus project (http://indus.projects.cis.ksu.edu).