Bug 500018 - Compiler problem with if() pointcut + parameter binding with auto-boxing
Summary: Compiler problem with if() pointcut + parameter binding with auto-boxing
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.8.9   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-08-20 04:48 EDT by Alexander Kriegisch CLA
Modified: 2016-08-20 04:48 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 Alexander Kriegisch CLA 2016-08-20 04:48:23 EDT
Hi Andy.

Eclipse Neon, AJDT 2.2.4.201607291758, AspectJ 1.8.9.201607291758

I had just answered a SO question:
http://stackoverflow.com/a/39051873/1082681

Everything works fine there. Then I found this SO question:
http://stackoverflow.com/questions/38938845/can-not-build-thisjoinpoint-lazily-for-this-advice-since-it-has-no-suitable-guar

It is about "no suitable guard" Lint warning.

Being lazy, I just extended the sample code from the previous question by switching on the warning usually ignored by default AJDT settings in Eclipse and - I actually turned the level to error - then trying to avoid the error by adding an if() pointcut as a guard. My updated sample code looks like this:

Driver application:

package de.scrum_master.app;

public class Application {
    public int getData(int i) {
        return i + i;
    }

    public Integer getMoreData(Integer i) {
        return i * i;
    }

    public String getSomethingElse(String string) {
        return string + " & " + string;
    }

    public static void main(String[] args) {
        Application application = new Application();
        application.getData(11);
        application.getMoreData(22);
        application.getSomethingElse("foo");
    }
}


Aspect:

package de.scrum_master.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class CacheOperationAspect {
    @Pointcut("execution(* de.scrum_master..get*Data(*)) && args(number) && if()")
    public static boolean cacheOperation(int number) {
        return true;
    }

    @Before("cacheOperation(number)")
    public void cacheOperationAdvice(JoinPoint thisJoinPoint, int number) {
        System.out.println(thisJoinPoint + " -> " + number);
    }
}

Suddenly I got this compiler error I did not get without the if() pointcut:

java.lang.RuntimeException
    at org.aspectj.apache.bcel.generic.InstructionFactory.createCast(InstructionFactory.java:472)
    at org.aspectj.weaver.bcel.Utility.createConversion(Utility.java:423)
    at org.aspectj.weaver.bcel.Utility.createConversion(Utility.java:349)
    at org.aspectj.weaver.bcel.BcelRenderer.renderExpr(BcelRenderer.java:73)
    at org.aspectj.weaver.bcel.BcelRenderer.visit(BcelRenderer.java:224)
    at org.aspectj.weaver.ast.Call.accep ...             POP
                    RETURN   (line 21)
  end public static void main(String[])

end public class de.scrum_master.app.Application

BTW, if I change the pointcut from
    execution(* de.scrum_master..get*Data(*)) ...
to
    execution(* de.scrum_master..get*Data(int))

the error goes away, but of course the behaviour is then different as it does not capture Integer arguments anymore, only int.