1

Below code is not complied correctly with aspectJ

import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ConfigurationCondition;
import org.springframework.context.annotation.ImportResource;
import org.springframework.core.type.AnnotatedTypeMetadata;

@Configuration
@Conditional(ConditionalConfiguration.Condition)
@ImportResource("/com/example/context-fragment.xml")
public class ConditionalConfiguration {
    static class Condition implements ConfigurationCondition {
         @Override  

         public ConfigurationPhase getConfigurationPhase() {
             return ConfigurationPhase.PARSE_CONFIGURATION;
         }          
         @Override
         public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
             // only load context-fragment.xml if the system property is defined
             return System.getProperty("com.example.context-fragment") != null;
         }
    }
}

I am using Eclipse Aspectj Tool. and the error is shown for @Conditional annotation.

The is as @Conditional:

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface Conditional {

    /**
     * All {@link Condition}s that must {@linkplain Condition#matches match}
     * in order for the component to be registered.
     */
    Class<? extends Condition>[] value();

}

The error is:

org.aspectj.weaver.BCException
at org.aspectj.ajdt.internal.core.builder.AjState.recordClassFile(AjState.java:1519)
at org.aspectj.ajdt.internal.core.builder.AjState.noteResult(AjState.java:1325)
at org.aspectj.ajdt.internal.core.builder.AjBuildManager$3.acceptResult(AjBuildManager.java:1061)
at org.aspectj.ajdt.internal.compiler.AjPipeliningCompilerAdapter.afterProcessing(AjPipeliningCompilerAdapter.java:426)
at org.aspectj.ajdt.intern ... .0_21-64\jre\lib\ext\sunmscapi.jar;E:\jdk1.7.0_21-64\jre\lib\ext\zipfs.jar;D:\eclipse\\plugins/org.eclipse.equinox.launcher_1.3.0.v20140415-2008.jar;

Any Idea how can I make it work, Or at least is it a way which I can set Eclipse AspectJ Tool to simply ignore this file.

kriegaex
  • 63,017
  • 15
  • 111
  • 202
Alireza Fattahi
  • 42,517
  • 14
  • 123
  • 173
  • If you have an AspectJ problem, please also post your aspect(s). and if it is an AspectJ compiler problem, please tell us the AspectJ version you use for compilation (the AJDT plugin version, if you use AJDT in Eclipse). Optimally, provide a reproduceable [SSCCE](http://sscce.org/). – kriegaex Dec 18 '14 at 11:14

1 Answers1

1

I was just able to reproduce your problem. Your code is wrong, not AspectJ. Change your annotation value like this:

@Conditional(ConditionalConfiguration.Condition.class)

You just forgot to use the .class suffix. Fix your own code, then the compiler will not complain anymore. ;-)

Update: Because your bug should not kill the AspectJ compiler anyway, I created a bug ticket for it, but the fact remains that your own code was bogus.

kriegaex
  • 63,017
  • 15
  • 111
  • 202
  • The org.aspectj.weaver.BCException was misleading me ! Thanks for answer, I found above code on stackovrflow (http://stackoverflow.com/questions/3035630/how-to-achieve-conditional-resource-import-in-a-spring-xml-context) , because my eclipse project was aspect enabled I never got the chance to see the actual compile error not the aspectJ issue. I am going to fix the code there ! – Alireza Fattahi Dec 18 '14 at 12:35
  • It isn't actually AspectJ that is wrong here, it is the Eclipse compiler that AspectJ is delegating to which is generating bad byte code. Because, post compilation, AspectJ immediately wants to dig into that byte code it immediately trips over the problem. I've raised an eclipse bug (https://bugs.eclipse.org/bugs/show_bug.cgi?id=456960) to get it fixed which AspectJ can then pick up. Using regular eclipse to compile that Java sample won't fail in the same way because Eclipse doesn't immediately check that the byte code is actually valid. Anyway, just FYI. – Andy Clement Jan 07 '15 at 19:23
  • Thanks Andy for following up on this issue. From a user perspective it is an *Ajc* problem because an average AspectJ user does not care or even know about which components *Ajc* uses internally. I as a frequent user do know it though and understand that you are dependent on other people solving the root cause of this problem. This is not a blocker anyway and I am happy that the Eclipse compiler people know about it and will fix it in due time. :-) – kriegaex Jan 08 '15 at 14:06