Bug 520135 - AspectJ Compile fails with wildcard return on function with "andThen" to var args when applying spring-aspects aspect
Summary: AspectJ Compile fails with wildcard return on function with "andThen" to var ...
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.8.10   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL: https://github.com/michaelwiles/aspec...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-07-25 06:04 EDT by Michael Wiles CLA
Modified: 2017-07-26 03:22 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 Michael Wiles CLA 2017-07-25 06:04:18 EDT
When I compile the following code examples with the spring-aspect aspect, compile fails:

github project is at: https://github.com/michaelwiles/aspectj-bug

Fail example:

public class FailsApectJ {

    private <T> Function<String, Collection<String>> ASpectJFailWithWildCardAndVarArgeMethodReference() {
        Function<T, ? extends Object> x = a -> a; // the wild card fails the compile
        x.andThen(this::get);
        return null;
    }

    private <T> List<T> get(T... args) {
        return Arrays.asList(args);
    }

}

Pass Example:

    private <T> Function<String, Collection<String>> noWildCardWithVarArgsMethodReference() {
        Function<T, Object> x = a -> a; // no wild card - passes
        x.andThen(this::get);
        return null;
    }

    private <T> List<T> get(T... args) {
        return Arrays.asList(args);
    }

    private <T> Function<String, Collection<String>> wildCardWithVarArgsNoMethodReference() {
        Function<T, ? extends Object> x = a -> a; // no wild card - passes
        x.andThen(t -> get(t));
        return null;
    }

Fails when there is a wild card, a var args and a method reference.

You can checkout the github project to replicate the issue.

Comments: The only aspect that I've found that exhibits the behaviour is the spring-aspect - I run a few others but none of them have the issue. So I'm not entirely sure exactly what pointcut or other exposes it.

The stack trace I get is:

[ERROR] abort trouble in: 
[ERROR] com.afrozaar.aspectj.test.FailsApectJ -- (IllegalStateException) Expecting [,L, or T, but found !Ljava while unpacking (!+Ljava/lang/Object;)Ljava/util/List<!+Ljava/lang/Object;>;
[ERROR] Expecting [,L, or T, but found !Ljava while unpacking (!+Ljava/lang/Object;)Ljava/util/List<!+Ljava/lang/Object;>;
[ERROR] java.lang.IllegalStateException: Expecting [,L, or T, but found !Ljava while unpacking (!+Ljava/lang/Object;)Ljava/util/List<!+Ljava/lang/Object;>;
[ERROR] 	at org.aspectj.util.GenericSignatureParser.parseFieldTypeSignature(GenericSignatureParser.java:159)
[ERROR] 	at org.aspectj.util.GenericSignatureParser.parseTypeArgument(GenericSignatureParser.java:251)
[ERROR] 	at org.aspectj.util.GenericSignatureParser.maybeParseTypeArguments(GenericSignatureParser.java:259)
[ERROR] 	at org.aspectj.util.GenericSignatureParser.parseClassTypeSignature(GenericSignatureParser.java:204)
[ERROR] 	at org.aspectj.util.GenericSignatureParser.parseFieldTypeSignature(GenericSignatureParser.java:155)
[ERROR] 	at org.aspectj.util.GenericSignatureParser.parseAsMethodSignature(GenericSignatureParser.java:99)
[ERROR] 	at org.aspectj.weaver.bcel.BcelMethod.unpackGenericSignature(BcelMethod.java:565)
[ERROR] 	at org.aspectj.weaver.bcel.BcelMethod.getGenericReturnType(BcelMethod.java:544)
[ERROR] 	at org.aspectj.weaver.JoinPointSignature.getGenericReturnType(JoinPointSignature.java:191)
[ERROR] 	at org.aspectj.weaver.patterns.SignaturePattern.matchesExactlyMethod(SignaturePattern.java:507)
[ERROR] 	at org.aspectj.weaver.patterns.SignaturePattern.matchesExactly(SignaturePattern.java:360)
[ERROR] 	at org.aspectj.weaver.patterns.SignaturePattern.matches(SignaturePattern.java:320)
[ERROR] 	at org.aspectj.weaver.patterns.KindedPointcut.matchInternal(KindedPointcut.java:197)
[ERROR] 	at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:137)
[ERROR] 	at org.aspectj.weaver.patterns.AndPointcut.matchInternal(AndPointcut.java:56)
[ERROR] 	at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:137)
[ERROR] 	at org.aspectj.weaver.patterns.OrPointcut.matchInternal(OrPointcut.java:56)
[ERROR] 	at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:137)
[ERROR] 	at org.aspectj.weaver.ShadowMunger.match(ShadowMunger.java:113)
[ERROR] 	at org.aspectj.weaver.Advice.match(Advice.java:109)
[ERROR] 	at org.aspectj.weaver.bcel.BcelAdvice.match(BcelAdvice.java:152)
[ERROR] 	at org.aspectj.weaver.bcel.BcelClassWeaver.match(BcelClassWeaver.java:3304)

Now I understand that it display an error - though the code compiles and runs fine.

The interesting thing is the original code which is a bit more complex failed did not fail with this error. It failed with this error:

java.lang.StringIndexOutOfBoundsException: String index out of range: 0
[ERROR] 	at java.lang.String.charAt(String.java:658)
[ERROR] 	at org.aspectj.weaver.UnresolvedType.forSignature(UnresolvedType.java:383)
[ERROR] 	at org.aspectj.weaver.TypeFactory.convertSigToType(TypeFactory.java:84)
[ERROR] 	at org.aspectj.weaver.TypeFactory.createTypeFromSignature(TypeFactory.java:159)
[ERROR] 	at org.aspectj.weaver.UnresolvedType.forSignature(UnresolvedType.java:409)
[ERROR] 	at org.aspectj.weaver.bcel.BcelGenericSignatureToTypeXConverter.typeSignature2TypeX(BcelGenericSignatureToTypeXConverter.java:199)
[ERROR] 	at org.aspectj.weaver.bcel.BcelGenericSignatureToTypeXConverter.typeSignature2TypeX(BcelGenericSignatureToTypeXConverter.java:189)
[ERROR] 	at org.aspectj.weaver.bcel.BcelMethod.unpackGenericSignature(BcelMethod.java:609)
[ERROR] 	at org.aspectj.weaver.bcel.BcelMethod.getGenericReturnType(BcelMethod.java:542)
[ERROR] 	at org.aspectj.weaver.JoinPointSignature.getGenericReturnType(JoinPointSignature.java:191)
[ERROR] 	at org.aspectj.weaver.patterns.SignaturePattern.matchesExactlyMethod(SignaturePattern.java:507)
[ERROR] 	at org.aspectj.weaver.patterns.SignaturePattern.matchesExactly(SignaturePattern.java:360)
[ERROR] 	at org.aspectj.weaver.patterns.SignaturePattern.matches(SignaturePattern.java:320)

If I remove the method reference from the original code it compiles successfully.

1.9.0.BETA-6 of aspectj also has the problem.

The work around of course, is obvious - don't use the method reference, or the var args or the wildcard.
Comment 1 Michael Wiles CLA 2017-07-26 03:22:48 EDT
My Apologies - I made a mistake with the second passing example: Should read wild card but passes when you remove the method reference.