1

Hi I am using AspectJ maven plugin and weaved the classes successfully at compile time however I am getting following issue:

java.lang.NoSuchFieldError: ajc$cflowCounter$0

Also pointcut as follows:

@Pointcut("execution(* *(..)) && cflowbelow(execution(* com.x.*..*(..)))")

pom.xml

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.11</version>
    <dependencies>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${aspectj.runtime.version}</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjtools</artifactId>
            <version>${aspectj.runtime.version}</version>
        </dependency>
    </dependencies>
    <configuration>
        <complianceLevel>${maven.compiler.target}</complianceLevel>
        <source>${maven.compiler.target}</source>
        <target>${maven.compiler.target}</target>
        <showWeaveInfo>true</showWeaveInfo>
        <verbose>true</verbose>
        <Xlint>ignore</Xlint>
        <encoding>${project.build.sourceEncoding}</encoding>
        <forceAjcCompile>true</forceAjcCompile>
        <sources />
        <weaveDirectories>
            <weaveDirectory>${project.build.directory}/classes</weaveDirectory>
        </weaveDirectories>
    </configuration>
    <executions>
        <execution>
            <phase>process-classes</phase>
            <goals>
                <goal>compile</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Error Log :

SEVERE: Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener]
java.lang.NoSuchFieldError: ajc$cflowCounter$0
    at com.x.util.PSMVPropertiesUtil.processProperties(PSMVPropertiesUtil.java)
    at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:86)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:164)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:693)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:409)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:291)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4745)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)

so the PSMVProperties is loaded and picked up at start of applcation

 protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props) throws BeansException {
        super.processProperties(beanFactory, props);

        propertiesMap = new HashMap<String, String>();
        for (Object key : props.keySet()) {
            String keyStr = key.toString();
            String valueStr = resolvePlaceholder(keyStr, props, springSystemPropertiesMode);
            propertiesMap.put(keyStr, valueStr);
        }
    }

What is causing this? How to solve this issue?

kriegaex
  • 63,017
  • 15
  • 111
  • 202
  • Could you please provide an [MCVE](https://stackoverflow.com/help/mcve), ideally on GitHub? I would like to analyse this. With the information available here I can only guess and I do not have a good idea other than you over-configured AspectJ Maven a bit. But that might not be the problem, I got to see for myself. Just give me the minimal project which reproduces the issue and does not reveal any company-internal information from your side. – kriegaex Oct 17 '19 at 07:32
  • sure. i will soon share minimal project implementation. – shubhra thakur Oct 17 '19 at 09:24
  • however i added true in pom.xml and it got resolved, got this when I was searching for similar issue. – shubhra thakur Oct 17 '19 at 09:30
  • I don't think this is the solution, rather hiding symptoms. If you need over-weaving, it means you are trying to weave previously woven classes. It would be interesting to know why this is necessary. I never needed this configuration switch before. Maybe you are trying to compile something twice which only needs to be compiled once. This could have negative side effects in the future. So the MCVE would still be useful, I can give you feedback after inspecting it. – kriegaex Oct 17 '19 at 09:44
  • ok I am on it and share it. – shubhra thakur Oct 17 '19 at 10:05
  • i am really unable to get the same error and what caused it. I have removed then too i m not getting the same error. – shubhra thakur Oct 22 '19 at 09:50
  • referred this [link]( https://community.pivotal.io/s/article/NoSuchFieldError-ajccflowCounter0-with-instrumented-Spring-together-with-Insight-enabled-tcServer-21-2015226 ) – shubhra thakur Oct 22 '19 at 09:56
  • If you cannot reproduce the error, there is nothing I can do to answer your question. The link you provided describes a similar problem but does not answer the question why you get the error when you (unnecessarily) activate overweaving. As I said, it is usually not needed, unless you know you want to weave classes which have been woven by the AspectJ compiler before. So which classes are you targetting there? Your own ones or Spring classes? I also don't know what `PSMVPropertiesUtil.processProperties(..)` does as you didn't share the source code. – kriegaex Oct 23 '19 at 07:23
  • i am working performance monitoring i am weaving all the classes inside ${project.build.directory}/classes for all modules. and keeping pointcut base package. Thus it also includes spring classes. – shubhra thakur Oct 23 '19 at 11:06
  • Actually there should not be any Spring classes in your build directory unless you configured your build to copy them there. And even if they were there for a good reason (which I doubt) you could always exclude them from weaving via `... && !within(org.springframework..*)`. I would not recommend to weave into Spring classes for performance monitoring reasons, rather jusr capture your own methods' execution time and maybe only `call(* org.springframework..*(..))` instead of `execution(..)`. – kriegaex Oct 24 '19 at 06:46
  • My guess is that your aspect might get picked up by the AspectJ load-time weaver if your have activated that one for any reason. Usually you do not need it if you use compile-time weaving, unless maybe you want to use AspectJ-based (as opposed to Spring AOP-based) transaction management in Spring, targetting non-Spring classes or private methods. You could just exclude the aspect from being woven once more or use LTW instead of CTW altogether. Anyway, I think you are doing something not quite right here. But this is just an educated guess because I have no MCVE. – kriegaex Oct 24 '19 at 06:50
  • LTW is not used. AspectJ-based only is used not spring-aop. I need to capture Time Took to complete the transaction and method execution time for spring classes as we as for non spring based. – shubhra thakur Oct 24 '19 at 07:18
  • ajc$cflowCounter$0 is not coming now.we can use AspectJ-based to capture transaction details of spring-based classes right ? as i need to capture for inner method also. – shubhra thakur Oct 24 '19 at 07:21
  • Sorry for answering late, I was very busy the last few weeks. Actually SO is not a discussion forum, so without an [MCVE](https://stackoverflow.com/help/mcve) I really cannot do more than speculate what might be the root cause of your problem. What I said before still applies: I think your build configuration is wrong in some way for this to be able to happen at all. – kriegaex Nov 03 '19 at 12:46

0 Answers0