Bug 149419 - Default access field injection fails
Summary: Default access field injection fails
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.5.2   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-07-02 18:23 EDT by Venkatesh Prasad Ranganath CLA
Modified: 2006-07-06 23:15 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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).