aspectj 1.8.[4, 9] - java.lang.IllegalStateException: Expecting raw type, not ...

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

aspectj 1.8.[4, 9] - java.lang.IllegalStateException: Expecting raw type, not ...

Stephen Evanchik
Hello,

I recently ran in to a problem with Spring AOP and AspectJ which appeared on this mailing list in March. I'm not sure what is going on because I've changed very little that would obviously cause this exception. There are many Generic types in the project that could/would be processed by AspectJ why this one is throwing things off is a mystery. I believe the reason this type is causing a problem now is because the concrete class used to be hidden behind a JDK Proxy so the AspectJ type evaluation did not see the concrete class and it's generic type. The class signature in question looks like this:

public class ConcreteClass extends AbstractClass<ConcreteType>

where AbstractClass<T> is defined as:

public abstract AbstractClass<T> extends AbstractSuperClass <T, ID> implements InterfaceOne InterfaceTwo<T>


Here's the stack trace:

Caused by: java.lang.IllegalStateException: Expecting raw type, not: ConcreteClass
    at org.aspectj.weaver.TypeFactory.createParameterizedType(TypeFactory.java:34)
    at org.aspectj.weaver.reflect.JavaLangTypeToResolvedTypeConverter.fromType(JavaLangTypeToResolvedTypeConverter.java:79)
    at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.getSuperclass(Java15ReflectionBasedReferenceTypeDelegate.java:156)
    at org.aspectj.weaver.ReferenceType.getSuperclass(ReferenceType.java:987)
    at org.aspectj.weaver.JoinPointSignatureIterator.addSignaturesUpToFirstDefiningMember(JoinPointSignatureIterator.java:95)
    at org.aspectj.weaver.JoinPointSignatureIterator.<init>(JoinPointSignatureIterator.java:49)
    at org.aspectj.weaver.MemberImpl.getJoinPointSignatures(MemberImpl.java:515)
    at org.aspectj.weaver.patterns.SignaturePattern.matches(SignaturePattern.java:316)
    at org.aspectj.weaver.patterns.KindedPointcut.matchInternal(KindedPointcut.java:197)
    at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:137)
    at org.aspectj.weaver.patterns.OrPointcut.matchInternal(OrPointcut.java:56)
    at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:137)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.getShadowMatch(PointcutExpressionImpl.java:319)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.matchesExecution(PointcutExpressionImpl.java:129)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.matchesMethodExecution(PointcutExpressionImpl.java:110)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.getShadowMatch(AspectJExpressionPointcut.java:408)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.matches(AspectJExpressionPointcut.java:266)
    at org.springframework.aop.support.MethodMatchers.matches(MethodMatchers.java:92)
    at org.springframework.aop.support.MethodMatchers$IntersectionMethodMatcher.matches(MethodMatchers.java:228)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:223)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:262)
    at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:294)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:118)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:88)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:69)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:361)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:324)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:409)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.postProcessObjectFromFactoryBean(AbstractAutowireCapableBeanFactory.java:1657)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:129)


I'm confused about this code in JavaLangTypeToResolvedTypeContainer.fromType():

...
        } else if (aType instanceof ParameterizedType) {
            ParameterizedType pt = (ParameterizedType) aType;
            ResolvedType baseType = fromType(pt.getRawType());
            Type[] args = pt.getActualTypeArguments();
            ResolvedType[] resolvedArgs = fromTypes(args);
            /*
             * StringBuilder sb = new StringBuilder(); for (int i = 0; i < resolvedArgs.length; i++) {
             * sb.append(resolvedArgs[i]).append(" "); } for (int i = 0; i < resolvedArgs.length; i++) { if (resolvedArgs[i] ==
             * null) { String ss = ""; try { ss = aType.toString(); } catch (Exception e) { } throw new
             * IllegalStateException("Parameterized type problem.  basetype=" + baseType + " arguments=" + sb.toString() + " ss=" +
             * ss); } }
             */
            return TypeFactory.createParameterizedType(baseType, resolvedArgs, getWorld());

..

and then TypeFactory.createParameterizedType(...):

        ResolvedType baseType = aBaseType;
        if (!aBaseType.isGenericType()) {
            // try and find the generic type...
            if (someTypeParameters != null && someTypeParameters.length > 0) {
                if (!aBaseType.isRawType()) {
                    throw new IllegalStateException("Expecting raw type, not: " + aBaseType);
                }
                baseType = baseType.getGenericType();
                if (baseType == null) {
                    throw new IllegalStateException("Raw type does not have generic type set");
                }
            } // else if someTypeParameters is null, then the base type is allowed to be non-generic, it's an inner
        }



because I don't understand why:

               if (!aBaseType.isRawType()) {
                    throw new IllegalStateException("Expecting raw type, not: " + aBaseType);
                }

aBaseType, which is a RawType from above, is evaluating to anything other than a raw type.


Stephen

_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: aspectj 1.8.[4, 9] - java.lang.IllegalStateException: Expecting raw type, not ...

Andy Clement
My immediate reaction is that:

ResolvedType baseType = fromType(pt.getRawType());

might be returning the generic type and not a raw type. But I’ve been trying to craft a test case based on your declarations and nothing is failing. Do you have a test case you can share that actually fails?

I recently ran in to a problem with Spring AOP and AspectJ which appeared on this mailing list in March.

I found that thread and it didn’t really come to a satisfying conclusion, so it would be good to get this sorted.

cheers,
Andy

On Apr 14, 2016, at 8:22 AM, Stephen Evanchik <[hidden email]> wrote:

Hello,

I recently ran in to a problem with Spring AOP and AspectJ which appeared on this mailing list in March. I'm not sure what is going on because I've changed very little that would obviously cause this exception. There are many Generic types in the project that could/would be processed by AspectJ why this one is throwing things off is a mystery. I believe the reason this type is causing a problem now is because the concrete class used to be hidden behind a JDK Proxy so the AspectJ type evaluation did not see the concrete class and it's generic type. The class signature in question looks like this:

public class ConcreteClass extends AbstractClass<ConcreteType>

where AbstractClass<T> is defined as:

public abstract AbstractClass<T> extends AbstractSuperClass <T, ID> implements InterfaceOne InterfaceTwo<T>


Here's the stack trace:

Caused by: java.lang.IllegalStateException: Expecting raw type, not: ConcreteClass
    at org.aspectj.weaver.TypeFactory.createParameterizedType(TypeFactory.java:34)
    at org.aspectj.weaver.reflect.JavaLangTypeToResolvedTypeConverter.fromType(JavaLangTypeToResolvedTypeConverter.java:79)
    at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.getSuperclass(Java15ReflectionBasedReferenceTypeDelegate.java:156)
    at org.aspectj.weaver.ReferenceType.getSuperclass(ReferenceType.java:987)
    at org.aspectj.weaver.JoinPointSignatureIterator.addSignaturesUpToFirstDefiningMember(JoinPointSignatureIterator.java:95)
    at org.aspectj.weaver.JoinPointSignatureIterator.<init>(JoinPointSignatureIterator.java:49)
    at org.aspectj.weaver.MemberImpl.getJoinPointSignatures(MemberImpl.java:515)
    at org.aspectj.weaver.patterns.SignaturePattern.matches(SignaturePattern.java:316)
    at org.aspectj.weaver.patterns.KindedPointcut.matchInternal(KindedPointcut.java:197)
    at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:137)
    at org.aspectj.weaver.patterns.OrPointcut.matchInternal(OrPointcut.java:56)
    at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:137)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.getShadowMatch(PointcutExpressionImpl.java:319)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.matchesExecution(PointcutExpressionImpl.java:129)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.matchesMethodExecution(PointcutExpressionImpl.java:110)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.getShadowMatch(AspectJExpressionPointcut.java:408)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.matches(AspectJExpressionPointcut.java:266)
    at org.springframework.aop.support.MethodMatchers.matches(MethodMatchers.java:92)
    at org.springframework.aop.support.MethodMatchers$IntersectionMethodMatcher.matches(MethodMatchers.java:228)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:223)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:262)
    at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:294)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:118)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:88)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:69)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:361)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:324)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:409)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.postProcessObjectFromFactoryBean(AbstractAutowireCapableBeanFactory.java:1657)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:129)


I'm confused about this code in JavaLangTypeToResolvedTypeContainer.fromType():

...
        } else if (aType instanceof ParameterizedType) {
            ParameterizedType pt = (ParameterizedType) aType;
            ResolvedType baseType = fromType(pt.getRawType());
            Type[] args = pt.getActualTypeArguments();
            ResolvedType[] resolvedArgs = fromTypes(args);
            /*
             * StringBuilder sb = new StringBuilder(); for (int i = 0; i < resolvedArgs.length; i++) {
             * sb.append(resolvedArgs[i]).append(" "); } for (int i = 0; i < resolvedArgs.length; i++) { if (resolvedArgs[i] ==
             * null) { String ss = ""; try { ss = aType.toString(); } catch (Exception e) { } throw new
             * IllegalStateException("Parameterized type problem.  basetype=" + baseType + " arguments=" + sb.toString() + " ss=" +
             * ss); } }
             */
            return TypeFactory.createParameterizedType(baseType, resolvedArgs, getWorld());

..

and then TypeFactory.createParameterizedType(...):

        ResolvedType baseType = aBaseType;
        if (!aBaseType.isGenericType()) {
            // try and find the generic type...
            if (someTypeParameters != null && someTypeParameters.length > 0) {
                if (!aBaseType.isRawType()) {
                    throw new IllegalStateException("Expecting raw type, not: " + aBaseType);
                }
                baseType = baseType.getGenericType();
                if (baseType == null) {
                    throw new IllegalStateException("Raw type does not have generic type set");
                }
            } // else if someTypeParameters is null, then the base type is allowed to be non-generic, it's an inner
        }



because I don't understand why:

               if (!aBaseType.isRawType()) {
                    throw new IllegalStateException("Expecting raw type, not: " + aBaseType);
                }

aBaseType, which is a RawType from above, is evaluating to anything other than a raw type.


Stephen
_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: aspectj 1.8.[4, 9] - java.lang.IllegalStateException: Expecting raw type, not ...

Stephen Evanchik
Hi Andy,

I have the AspectJ source tree pulled down and will look in to generating a test. Any pointers would be appreciated; it looks I need to modify something in weaver5's test area, is that right?

            ResolvedType baseType = fromType(pt.getRawType());

This returns Class<?> of AbstractClass (so no generics as far as I can tell). However, in TypeFactory:

                if (!aBaseType.isRawType()) {


returns false because the typeKind == SIMPLE.

I think that's the bug, why it is that value is beyond me.

Stephen



On Fri, Apr 15, 2016 at 7:49 PM, Andy Clement <[hidden email]> wrote:
My immediate reaction is that:

ResolvedType baseType = fromType(pt.getRawType());

might be returning the generic type and not a raw type. But I’ve been trying to craft a test case based on your declarations and nothing is failing. Do you have a test case you can share that actually fails?

I recently ran in to a problem with Spring AOP and AspectJ which appeared on this mailing list in March.

I found that thread and it didn’t really come to a satisfying conclusion, so it would be good to get this sorted.

cheers,
Andy

On Apr 14, 2016, at 8:22 AM, Stephen Evanchik <[hidden email]> wrote:

Hello,

I recently ran in to a problem with Spring AOP and AspectJ which appeared on this mailing list in March. I'm not sure what is going on because I've changed very little that would obviously cause this exception. There are many Generic types in the project that could/would be processed by AspectJ why this one is throwing things off is a mystery. I believe the reason this type is causing a problem now is because the concrete class used to be hidden behind a JDK Proxy so the AspectJ type evaluation did not see the concrete class and it's generic type. The class signature in question looks like this:

public class ConcreteClass extends AbstractClass<ConcreteType>

where AbstractClass<T> is defined as:

public abstract AbstractClass<T> extends AbstractSuperClass <T, ID> implements InterfaceOne InterfaceTwo<T>


Here's the stack trace:

Caused by: java.lang.IllegalStateException: Expecting raw type, not: ConcreteClass
    at org.aspectj.weaver.TypeFactory.createParameterizedType(TypeFactory.java:34)
    at org.aspectj.weaver.reflect.JavaLangTypeToResolvedTypeConverter.fromType(JavaLangTypeToResolvedTypeConverter.java:79)
    at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.getSuperclass(Java15ReflectionBasedReferenceTypeDelegate.java:156)
    at org.aspectj.weaver.ReferenceType.getSuperclass(ReferenceType.java:987)
    at org.aspectj.weaver.JoinPointSignatureIterator.addSignaturesUpToFirstDefiningMember(JoinPointSignatureIterator.java:95)
    at org.aspectj.weaver.JoinPointSignatureIterator.<init>(JoinPointSignatureIterator.java:49)
    at org.aspectj.weaver.MemberImpl.getJoinPointSignatures(MemberImpl.java:515)
    at org.aspectj.weaver.patterns.SignaturePattern.matches(SignaturePattern.java:316)
    at org.aspectj.weaver.patterns.KindedPointcut.matchInternal(KindedPointcut.java:197)
    at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:137)
    at org.aspectj.weaver.patterns.OrPointcut.matchInternal(OrPointcut.java:56)
    at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:137)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.getShadowMatch(PointcutExpressionImpl.java:319)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.matchesExecution(PointcutExpressionImpl.java:129)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.matchesMethodExecution(PointcutExpressionImpl.java:110)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.getShadowMatch(AspectJExpressionPointcut.java:408)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.matches(AspectJExpressionPointcut.java:266)
    at org.springframework.aop.support.MethodMatchers.matches(MethodMatchers.java:92)
    at org.springframework.aop.support.MethodMatchers$IntersectionMethodMatcher.matches(MethodMatchers.java:228)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:223)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:262)
    at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:294)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:118)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:88)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:69)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:361)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:324)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:409)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.postProcessObjectFromFactoryBean(AbstractAutowireCapableBeanFactory.java:1657)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:129)


I'm confused about this code in JavaLangTypeToResolvedTypeContainer.fromType():

...
        } else if (aType instanceof ParameterizedType) {
            ParameterizedType pt = (ParameterizedType) aType;
            ResolvedType baseType = fromType(pt.getRawType());
            Type[] args = pt.getActualTypeArguments();
            ResolvedType[] resolvedArgs = fromTypes(args);
            /*
             * StringBuilder sb = new StringBuilder(); for (int i = 0; i < resolvedArgs.length; i++) {
             * sb.append(resolvedArgs[i]).append(" "); } for (int i = 0; i < resolvedArgs.length; i++) { if (resolvedArgs[i] ==
             * null) { String ss = ""; try { ss = aType.toString(); } catch (Exception e) { } throw new
             * IllegalStateException("Parameterized type problem.  basetype=" + baseType + " arguments=" + sb.toString() + " ss=" +
             * ss); } }
             */
            return TypeFactory.createParameterizedType(baseType, resolvedArgs, getWorld());

..

and then TypeFactory.createParameterizedType(...):

        ResolvedType baseType = aBaseType;
        if (!aBaseType.isGenericType()) {
            // try and find the generic type...
            if (someTypeParameters != null && someTypeParameters.length > 0) {
                if (!aBaseType.isRawType()) {
                    throw new IllegalStateException("Expecting raw type, not: " + aBaseType);
                }
                baseType = baseType.getGenericType();
                if (baseType == null) {
                    throw new IllegalStateException("Raw type does not have generic type set");
                }
            } // else if someTypeParameters is null, then the base type is allowed to be non-generic, it's an inner
        }



because I don't understand why:

               if (!aBaseType.isRawType()) {
                    throw new IllegalStateException("Expecting raw type, not: " + aBaseType);
                }

aBaseType, which is a RawType from above, is evaluating to anything other than a raw type.


Stephen
_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev



--

_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: aspectj 1.8.[4, 9] - java.lang.IllegalStateException: Expecting raw type, not ...

Andy Clement
Hey Stephen,

If you can share a program with me that fails I’m happy to dive into it, rather than you having to dive into working how to build a test. I was crafting tests in ReflectionWorldTest in weaver5 but nothing basic was triggering the issue, possibly because of something that happens earlier that I don’t know about. 

If you want to debug further yourself, stick a breakpoint in TypeMap.put() and look at what is happening when it puts the SIMPLE form of AbstractClass in there. Why did it build the SIMPLE form and not the raw or generic.

But as I say, I’m happy to look, but I just can’t recreate the problem.

cheers,
Andy

On Apr 18, 2016, at 11:16 AM, Stephen Evanchik <[hidden email]> wrote:

Hi Andy,

I have the AspectJ source tree pulled down and will look in to generating a test. Any pointers would be appreciated; it looks I need to modify something in weaver5's test area, is that right?

            ResolvedType baseType = fromType(pt.getRawType());

This returns Class<?> of AbstractClass (so no generics as far as I can tell). However, in TypeFactory:

                if (!aBaseType.isRawType()) {


returns false because the typeKind == SIMPLE.

I think that's the bug, why it is that value is beyond me.

Stephen



On Fri, Apr 15, 2016 at 7:49 PM, Andy Clement <[hidden email]> wrote:
My immediate reaction is that:

ResolvedType baseType = fromType(pt.getRawType());

might be returning the generic type and not a raw type. But I’ve been trying to craft a test case based on your declarations and nothing is failing. Do you have a test case you can share that actually fails?

I recently ran in to a problem with Spring AOP and AspectJ which appeared on this mailing list in March.

I found that thread and it didn’t really come to a satisfying conclusion, so it would be good to get this sorted.

cheers,
Andy

On Apr 14, 2016, at 8:22 AM, Stephen Evanchik <[hidden email]> wrote:

Hello,

I recently ran in to a problem with Spring AOP and AspectJ which appeared on this mailing list in March. I'm not sure what is going on because I've changed very little that would obviously cause this exception. There are many Generic types in the project that could/would be processed by AspectJ why this one is throwing things off is a mystery. I believe the reason this type is causing a problem now is because the concrete class used to be hidden behind a JDK Proxy so the AspectJ type evaluation did not see the concrete class and it's generic type. The class signature in question looks like this:

public class ConcreteClass extends AbstractClass<ConcreteType>

where AbstractClass<T> is defined as:

public abstract AbstractClass<T> extends AbstractSuperClass <T, ID> implements InterfaceOne InterfaceTwo<T>


Here's the stack trace:

Caused by: java.lang.IllegalStateException: Expecting raw type, not: ConcreteClass
    at org.aspectj.weaver.TypeFactory.createParameterizedType(TypeFactory.java:34)
    at org.aspectj.weaver.reflect.JavaLangTypeToResolvedTypeConverter.fromType(JavaLangTypeToResolvedTypeConverter.java:79)
    at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.getSuperclass(Java15ReflectionBasedReferenceTypeDelegate.java:156)
    at org.aspectj.weaver.ReferenceType.getSuperclass(ReferenceType.java:987)
    at org.aspectj.weaver.JoinPointSignatureIterator.addSignaturesUpToFirstDefiningMember(JoinPointSignatureIterator.java:95)
    at org.aspectj.weaver.JoinPointSignatureIterator.<init>(JoinPointSignatureIterator.java:49)
    at org.aspectj.weaver.MemberImpl.getJoinPointSignatures(MemberImpl.java:515)
    at org.aspectj.weaver.patterns.SignaturePattern.matches(SignaturePattern.java:316)
    at org.aspectj.weaver.patterns.KindedPointcut.matchInternal(KindedPointcut.java:197)
    at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:137)
    at org.aspectj.weaver.patterns.OrPointcut.matchInternal(OrPointcut.java:56)
    at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:137)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.getShadowMatch(PointcutExpressionImpl.java:319)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.matchesExecution(PointcutExpressionImpl.java:129)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.matchesMethodExecution(PointcutExpressionImpl.java:110)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.getShadowMatch(AspectJExpressionPointcut.java:408)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.matches(AspectJExpressionPointcut.java:266)
    at org.springframework.aop.support.MethodMatchers.matches(MethodMatchers.java:92)
    at org.springframework.aop.support.MethodMatchers$IntersectionMethodMatcher.matches(MethodMatchers.java:228)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:223)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:262)
    at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:294)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:118)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:88)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:69)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:361)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:324)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:409)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.postProcessObjectFromFactoryBean(AbstractAutowireCapableBeanFactory.java:1657)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:129)


I'm confused about this code in JavaLangTypeToResolvedTypeContainer.fromType():

...
        } else if (aType instanceof ParameterizedType) {
            ParameterizedType pt = (ParameterizedType) aType;
            ResolvedType baseType = fromType(pt.getRawType());
            Type[] args = pt.getActualTypeArguments();
            ResolvedType[] resolvedArgs = fromTypes(args);
            /*
             * StringBuilder sb = new StringBuilder(); for (int i = 0; i < resolvedArgs.length; i++) {
             * sb.append(resolvedArgs[i]).append(" "); } for (int i = 0; i < resolvedArgs.length; i++) { if (resolvedArgs[i] ==
             * null) { String ss = ""; try { ss = aType.toString(); } catch (Exception e) { } throw new
             * IllegalStateException("Parameterized type problem.  basetype=" + baseType + " arguments=" + sb.toString() + " ss=" +
             * ss); } }
             */
            return TypeFactory.createParameterizedType(baseType, resolvedArgs, getWorld());

..

and then TypeFactory.createParameterizedType(...):

        ResolvedType baseType = aBaseType;
        if (!aBaseType.isGenericType()) {
            // try and find the generic type...
            if (someTypeParameters != null && someTypeParameters.length > 0) {
                if (!aBaseType.isRawType()) {
                    throw new IllegalStateException("Expecting raw type, not: " + aBaseType);
                }
                baseType = baseType.getGenericType();
                if (baseType == null) {
                    throw new IllegalStateException("Raw type does not have generic type set");
                }
            } // else if someTypeParameters is null, then the base type is allowed to be non-generic, it's an inner
        }



because I don't understand why:

               if (!aBaseType.isRawType()) {
                    throw new IllegalStateException("Expecting raw type, not: " + aBaseType);
                }

aBaseType, which is a RawType from above, is evaluating to anything other than a raw type.


Stephen
_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev



--
_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: aspectj 1.8.[4, 9] - java.lang.IllegalStateException: Expecting raw type, not ...

Stephen Evanchik
Hi Andy,

I recreated the class hierarchy in weaver5's test tree. I have a simple test which is trying to resolve the class using ReflectionWorld. I always see a typeKind of RAW and never simple.

I even went to the trouble of naming every class and package exactly as what is in the running program. Unfortunately, capturing what is going on in the program is difficult due to the amount of initialization that occurs just before the fatal exception. I'll try a conditional breakpoint and see if I can get that working.



Stephen

On Mon, Apr 18, 2016 at 5:41 PM, Andy Clement <[hidden email]> wrote:
Hey Stephen,

If you can share a program with me that fails I’m happy to dive into it, rather than you having to dive into working how to build a test. I was crafting tests in ReflectionWorldTest in weaver5 but nothing basic was triggering the issue, possibly because of something that happens earlier that I don’t know about. 

If you want to debug further yourself, stick a breakpoint in TypeMap.put() and look at what is happening when it puts the SIMPLE form of AbstractClass in there. Why did it build the SIMPLE form and not the raw or generic.

But as I say, I’m happy to look, but I just can’t recreate the problem.

cheers,
Andy

On Apr 18, 2016, at 11:16 AM, Stephen Evanchik <[hidden email]> wrote:

Hi Andy,

I have the AspectJ source tree pulled down and will look in to generating a test. Any pointers would be appreciated; it looks I need to modify something in weaver5's test area, is that right?

            ResolvedType baseType = fromType(pt.getRawType());

This returns Class<?> of AbstractClass (so no generics as far as I can tell). However, in TypeFactory:

                if (!aBaseType.isRawType()) {


returns false because the typeKind == SIMPLE.

I think that's the bug, why it is that value is beyond me.

Stephen



On Fri, Apr 15, 2016 at 7:49 PM, Andy Clement <[hidden email]> wrote:
My immediate reaction is that:

ResolvedType baseType = fromType(pt.getRawType());

might be returning the generic type and not a raw type. But I’ve been trying to craft a test case based on your declarations and nothing is failing. Do you have a test case you can share that actually fails?

I recently ran in to a problem with Spring AOP and AspectJ which appeared on this mailing list in March.

I found that thread and it didn’t really come to a satisfying conclusion, so it would be good to get this sorted.

cheers,
Andy

On Apr 14, 2016, at 8:22 AM, Stephen Evanchik <[hidden email]> wrote:

Hello,

I recently ran in to a problem with Spring AOP and AspectJ which appeared on this mailing list in March. I'm not sure what is going on because I've changed very little that would obviously cause this exception. There are many Generic types in the project that could/would be processed by AspectJ why this one is throwing things off is a mystery. I believe the reason this type is causing a problem now is because the concrete class used to be hidden behind a JDK Proxy so the AspectJ type evaluation did not see the concrete class and it's generic type. The class signature in question looks like this:

public class ConcreteClass extends AbstractClass<ConcreteType>

where AbstractClass<T> is defined as:

public abstract AbstractClass<T> extends AbstractSuperClass <T, ID> implements InterfaceOne InterfaceTwo<T>


Here's the stack trace:

Caused by: java.lang.IllegalStateException: Expecting raw type, not: ConcreteClass
    at org.aspectj.weaver.TypeFactory.createParameterizedType(TypeFactory.java:34)
    at org.aspectj.weaver.reflect.JavaLangTypeToResolvedTypeConverter.fromType(JavaLangTypeToResolvedTypeConverter.java:79)
    at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.getSuperclass(Java15ReflectionBasedReferenceTypeDelegate.java:156)
    at org.aspectj.weaver.ReferenceType.getSuperclass(ReferenceType.java:987)
    at org.aspectj.weaver.JoinPointSignatureIterator.addSignaturesUpToFirstDefiningMember(JoinPointSignatureIterator.java:95)
    at org.aspectj.weaver.JoinPointSignatureIterator.<init>(JoinPointSignatureIterator.java:49)
    at org.aspectj.weaver.MemberImpl.getJoinPointSignatures(MemberImpl.java:515)
    at org.aspectj.weaver.patterns.SignaturePattern.matches(SignaturePattern.java:316)
    at org.aspectj.weaver.patterns.KindedPointcut.matchInternal(KindedPointcut.java:197)
    at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:137)
    at org.aspectj.weaver.patterns.OrPointcut.matchInternal(OrPointcut.java:56)
    at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:137)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.getShadowMatch(PointcutExpressionImpl.java:319)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.matchesExecution(PointcutExpressionImpl.java:129)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.matchesMethodExecution(PointcutExpressionImpl.java:110)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.getShadowMatch(AspectJExpressionPointcut.java:408)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.matches(AspectJExpressionPointcut.java:266)
    at org.springframework.aop.support.MethodMatchers.matches(MethodMatchers.java:92)
    at org.springframework.aop.support.MethodMatchers$IntersectionMethodMatcher.matches(MethodMatchers.java:228)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:223)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:262)
    at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:294)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:118)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:88)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:69)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:361)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:324)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:409)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.postProcessObjectFromFactoryBean(AbstractAutowireCapableBeanFactory.java:1657)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:129)


I'm confused about this code in JavaLangTypeToResolvedTypeContainer.fromType():

...
        } else if (aType instanceof ParameterizedType) {
            ParameterizedType pt = (ParameterizedType) aType;
            ResolvedType baseType = fromType(pt.getRawType());
            Type[] args = pt.getActualTypeArguments();
            ResolvedType[] resolvedArgs = fromTypes(args);
            /*
             * StringBuilder sb = new StringBuilder(); for (int i = 0; i < resolvedArgs.length; i++) {
             * sb.append(resolvedArgs[i]).append(" "); } for (int i = 0; i < resolvedArgs.length; i++) { if (resolvedArgs[i] ==
             * null) { String ss = ""; try { ss = aType.toString(); } catch (Exception e) { } throw new
             * IllegalStateException("Parameterized type problem.  basetype=" + baseType + " arguments=" + sb.toString() + " ss=" +
             * ss); } }
             */
            return TypeFactory.createParameterizedType(baseType, resolvedArgs, getWorld());

..

and then TypeFactory.createParameterizedType(...):

        ResolvedType baseType = aBaseType;
        if (!aBaseType.isGenericType()) {
            // try and find the generic type...
            if (someTypeParameters != null && someTypeParameters.length > 0) {
                if (!aBaseType.isRawType()) {
                    throw new IllegalStateException("Expecting raw type, not: " + aBaseType);
                }
                baseType = baseType.getGenericType();
                if (baseType == null) {
                    throw new IllegalStateException("Raw type does not have generic type set");
                }
            } // else if someTypeParameters is null, then the base type is allowed to be non-generic, it's an inner
        }



because I don't understand why:

               if (!aBaseType.isRawType()) {
                    throw new IllegalStateException("Expecting raw type, not: " + aBaseType);
                }

aBaseType, which is a RawType from above, is evaluating to anything other than a raw type.


Stephen
_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev



--
_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev



--

_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: aspectj 1.8.[4, 9] - java.lang.IllegalStateException: Expecting raw type, not ...

Stephen Evanchik
Hi Andy,

I think I understand where the TypeKind SIMPLE shows up. In the following code:

        } else if (aType instanceof ParameterizedType) {
            ParameterizedType pt = (ParameterizedType) aType;
            ResolvedType baseType = fromType(pt.getRawType());

pt is correctly a ParameterizedTypeImpl whose .toString() shows the correct type package.Type<ParameterType> . The pt.getRawType() returns a Class whose .toString() yields the simple package.Type. This gets fed to:

        if (aType instanceof Class) {
            Class clazz = (Class) aType;
            String name = clazz.getName();
            /**
             * getName() can return:
             *
             * 1. If this class object represents a reference type that is not an array type then the binary name of the class is
             * returned 2. If this class object represents a primitive type or void, then the name returned is a String equal to the
             * Java language keyword corresponding to the primitive type or void. 3. If this class object represents a class of
             * arrays, then the internal form of the name consists of the name of the element type preceded by one or more '['
             * characters representing the depth of the array nesting.
             */
            if (clazz.isArray()) {
                UnresolvedType ut = UnresolvedType.forSignature(name.replace('.', '/'));
                return getWorld().resolve(ut);
            } else {
                return getWorld().resolve(name);
            }

This is where things start to get interesting, resolve(<String>) is implemented as:

    public ResolvedType resolve(String name) {
        // trace.enter("resolve", this, new Object[] {name});
        ResolvedType ret = resolve(UnresolvedType.forName(name));
        // trace.exit("resolve", ret);
        return ret;
    }


and I believe the problem is that UnresolvedType.forName() is where the raw type information is finally and completely lost. At some point the UnresolvedType is created in TypeFactory:

        } else if (firstChar == 'L') {
            // only an issue if there is also an angle bracket
            int leftAngleBracket = signature.indexOf('<');

            if (leftAngleBracket == -1) {
                return new UnresolvedType(signature);

This is where things go wrong as the default TypeKind == SIMPLE but we're working with a type that has been erased (If I understand all of this terminology correctly).

Stephen


On Tue, May 3, 2016 at 2:40 PM, Stephen Evanchik <[hidden email]> wrote:
Hi Andy,

I recreated the class hierarchy in weaver5's test tree. I have a simple test which is trying to resolve the class using ReflectionWorld. I always see a typeKind of RAW and never simple.

I even went to the trouble of naming every class and package exactly as what is in the running program. Unfortunately, capturing what is going on in the program is difficult due to the amount of initialization that occurs just before the fatal exception. I'll try a conditional breakpoint and see if I can get that working.



Stephen

On Mon, Apr 18, 2016 at 5:41 PM, Andy Clement <[hidden email]> wrote:
Hey Stephen,

If you can share a program with me that fails I’m happy to dive into it, rather than you having to dive into working how to build a test. I was crafting tests in ReflectionWorldTest in weaver5 but nothing basic was triggering the issue, possibly because of something that happens earlier that I don’t know about. 

If you want to debug further yourself, stick a breakpoint in TypeMap.put() and look at what is happening when it puts the SIMPLE form of AbstractClass in there. Why did it build the SIMPLE form and not the raw or generic.

But as I say, I’m happy to look, but I just can’t recreate the problem.

cheers,
Andy

On Apr 18, 2016, at 11:16 AM, Stephen Evanchik <[hidden email]> wrote:

Hi Andy,

I have the AspectJ source tree pulled down and will look in to generating a test. Any pointers would be appreciated; it looks I need to modify something in weaver5's test area, is that right?

            ResolvedType baseType = fromType(pt.getRawType());

This returns Class<?> of AbstractClass (so no generics as far as I can tell). However, in TypeFactory:

                if (!aBaseType.isRawType()) {


returns false because the typeKind == SIMPLE.

I think that's the bug, why it is that value is beyond me.

Stephen



On Fri, Apr 15, 2016 at 7:49 PM, Andy Clement <[hidden email]> wrote:
My immediate reaction is that:

ResolvedType baseType = fromType(pt.getRawType());

might be returning the generic type and not a raw type. But I’ve been trying to craft a test case based on your declarations and nothing is failing. Do you have a test case you can share that actually fails?

I recently ran in to a problem with Spring AOP and AspectJ which appeared on this mailing list in March.

I found that thread and it didn’t really come to a satisfying conclusion, so it would be good to get this sorted.

cheers,
Andy

On Apr 14, 2016, at 8:22 AM, Stephen Evanchik <[hidden email]> wrote:

Hello,

I recently ran in to a problem with Spring AOP and AspectJ which appeared on this mailing list in March. I'm not sure what is going on because I've changed very little that would obviously cause this exception. There are many Generic types in the project that could/would be processed by AspectJ why this one is throwing things off is a mystery. I believe the reason this type is causing a problem now is because the concrete class used to be hidden behind a JDK Proxy so the AspectJ type evaluation did not see the concrete class and it's generic type. The class signature in question looks like this:

public class ConcreteClass extends AbstractClass<ConcreteType>

where AbstractClass<T> is defined as:

public abstract AbstractClass<T> extends AbstractSuperClass <T, ID> implements InterfaceOne InterfaceTwo<T>


Here's the stack trace:

Caused by: java.lang.IllegalStateException: Expecting raw type, not: ConcreteClass
    at org.aspectj.weaver.TypeFactory.createParameterizedType(TypeFactory.java:34)
    at org.aspectj.weaver.reflect.JavaLangTypeToResolvedTypeConverter.fromType(JavaLangTypeToResolvedTypeConverter.java:79)
    at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.getSuperclass(Java15ReflectionBasedReferenceTypeDelegate.java:156)
    at org.aspectj.weaver.ReferenceType.getSuperclass(ReferenceType.java:987)
    at org.aspectj.weaver.JoinPointSignatureIterator.addSignaturesUpToFirstDefiningMember(JoinPointSignatureIterator.java:95)
    at org.aspectj.weaver.JoinPointSignatureIterator.<init>(JoinPointSignatureIterator.java:49)
    at org.aspectj.weaver.MemberImpl.getJoinPointSignatures(MemberImpl.java:515)
    at org.aspectj.weaver.patterns.SignaturePattern.matches(SignaturePattern.java:316)
    at org.aspectj.weaver.patterns.KindedPointcut.matchInternal(KindedPointcut.java:197)
    at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:137)
    at org.aspectj.weaver.patterns.OrPointcut.matchInternal(OrPointcut.java:56)
    at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:137)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.getShadowMatch(PointcutExpressionImpl.java:319)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.matchesExecution(PointcutExpressionImpl.java:129)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.matchesMethodExecution(PointcutExpressionImpl.java:110)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.getShadowMatch(AspectJExpressionPointcut.java:408)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.matches(AspectJExpressionPointcut.java:266)
    at org.springframework.aop.support.MethodMatchers.matches(MethodMatchers.java:92)
    at org.springframework.aop.support.MethodMatchers$IntersectionMethodMatcher.matches(MethodMatchers.java:228)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:223)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:262)
    at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:294)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:118)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:88)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:69)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:361)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:324)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:409)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.postProcessObjectFromFactoryBean(AbstractAutowireCapableBeanFactory.java:1657)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:129)


I'm confused about this code in JavaLangTypeToResolvedTypeContainer.fromType():

...
        } else if (aType instanceof ParameterizedType) {
            ParameterizedType pt = (ParameterizedType) aType;
            ResolvedType baseType = fromType(pt.getRawType());
            Type[] args = pt.getActualTypeArguments();
            ResolvedType[] resolvedArgs = fromTypes(args);
            /*
             * StringBuilder sb = new StringBuilder(); for (int i = 0; i < resolvedArgs.length; i++) {
             * sb.append(resolvedArgs[i]).append(" "); } for (int i = 0; i < resolvedArgs.length; i++) { if (resolvedArgs[i] ==
             * null) { String ss = ""; try { ss = aType.toString(); } catch (Exception e) { } throw new
             * IllegalStateException("Parameterized type problem.  basetype=" + baseType + " arguments=" + sb.toString() + " ss=" +
             * ss); } }
             */
            return TypeFactory.createParameterizedType(baseType, resolvedArgs, getWorld());

..

and then TypeFactory.createParameterizedType(...):

        ResolvedType baseType = aBaseType;
        if (!aBaseType.isGenericType()) {
            // try and find the generic type...
            if (someTypeParameters != null && someTypeParameters.length > 0) {
                if (!aBaseType.isRawType()) {
                    throw new IllegalStateException("Expecting raw type, not: " + aBaseType);
                }
                baseType = baseType.getGenericType();
                if (baseType == null) {
                    throw new IllegalStateException("Raw type does not have generic type set");
                }
            } // else if someTypeParameters is null, then the base type is allowed to be non-generic, it's an inner
        }



because I don't understand why:

               if (!aBaseType.isRawType()) {
                    throw new IllegalStateException("Expecting raw type, not: " + aBaseType);
                }

aBaseType, which is a RawType from above, is evaluating to anything other than a raw type.


Stephen
_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev



--
_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev



--



--

_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: aspectj 1.8.[4, 9] - java.lang.IllegalStateException: Expecting raw type, not ...

Andy Clement
Hi,

Certainly sounds like the right area.

Although simple types get saved into the type map, if we later discover there are generic variants it should get ‘promoted’ from simple - a call to setGenericType() on ReferenceType will promote it to raw.

So if resolution (via resolve) did put a simple type in the map, why did it not get promoted to raw when the parameterized variant is dealt with? Did setGenericType not get called?

I still feel it is the use of reflection world than is contributing to the problem and things are not happening the same as they would with a bcelworld backend. We have thousands of tests for bcelworld and comparatively very few for reflection world.

Any closer to sharing a test case? When we do end up putting fixes around in this area, we will need at least one to add to the regression suite.

cheers,
Andy

On May 16, 2016, at 9:26 AM, Stephen Evanchik <[hidden email]> wrote:

Hi Andy,

I think I understand where the TypeKind SIMPLE shows up. In the following code:

        } else if (aType instanceof ParameterizedType) {
            ParameterizedType pt = (ParameterizedType) aType;
            ResolvedType baseType = fromType(pt.getRawType());

pt is correctly a ParameterizedTypeImpl whose .toString() shows the correct type package.Type<ParameterType> . The pt.getRawType() returns a Class whose .toString() yields the simple package.Type. This gets fed to:

        if (aType instanceof Class) {
            Class clazz = (Class) aType;
            String name = clazz.getName();
            /**
             * getName() can return:
             * 
             * 1. If this class object represents a reference type that is not an array type then the binary name of the class is
             * returned 2. If this class object represents a primitive type or void, then the name returned is a String equal to the
             * Java language keyword corresponding to the primitive type or void. 3. If this class object represents a class of
             * arrays, then the internal form of the name consists of the name of the element type preceded by one or more '['
             * characters representing the depth of the array nesting.
             */
            if (clazz.isArray()) {
                UnresolvedType ut = UnresolvedType.forSignature(name.replace('.', '/'));
                return getWorld().resolve(ut);
            } else {
                return getWorld().resolve(name);
            }

This is where things start to get interesting, resolve(<String>) is implemented as:

    public ResolvedType resolve(String name) {
        // trace.enter("resolve", this, new Object[] {name});
        ResolvedType ret = resolve(UnresolvedType.forName(name));
        // trace.exit("resolve", ret);
        return ret;
    }


and I believe the problem is that UnresolvedType.forName() is where the raw type information is finally and completely lost. At some point the UnresolvedType is created in TypeFactory:

        } else if (firstChar == 'L') {
            // only an issue if there is also an angle bracket
            int leftAngleBracket = signature.indexOf('<');

            if (leftAngleBracket == -1) {
                return new UnresolvedType(signature);

This is where things go wrong as the default TypeKind == SIMPLE but we're working with a type that has been erased (If I understand all of this terminology correctly).

Stephen


On Tue, May 3, 2016 at 2:40 PM, Stephen Evanchik <[hidden email]> wrote:
Hi Andy,

I recreated the class hierarchy in weaver5's test tree. I have a simple test which is trying to resolve the class using ReflectionWorld. I always see a typeKind of RAW and never simple.

I even went to the trouble of naming every class and package exactly as what is in the running program. Unfortunately, capturing what is going on in the program is difficult due to the amount of initialization that occurs just before the fatal exception. I'll try a conditional breakpoint and see if I can get that working.



Stephen

On Mon, Apr 18, 2016 at 5:41 PM, Andy Clement <[hidden email]> wrote:
Hey Stephen,

If you can share a program with me that fails I’m happy to dive into it, rather than you having to dive into working how to build a test. I was crafting tests in ReflectionWorldTest in weaver5 but nothing basic was triggering the issue, possibly because of something that happens earlier that I don’t know about. 

If you want to debug further yourself, stick a breakpoint in TypeMap.put() and look at what is happening when it puts the SIMPLE form of AbstractClass in there. Why did it build the SIMPLE form and not the raw or generic.

But as I say, I’m happy to look, but I just can’t recreate the problem.

cheers,
Andy

On Apr 18, 2016, at 11:16 AM, Stephen Evanchik <[hidden email]> wrote:

Hi Andy,

I have the AspectJ source tree pulled down and will look in to generating a test. Any pointers would be appreciated; it looks I need to modify something in weaver5's test area, is that right?

            ResolvedType baseType = fromType(pt.getRawType());

This returns Class<?> of AbstractClass (so no generics as far as I can tell). However, in TypeFactory:

                if (!aBaseType.isRawType()) {


returns false because the typeKind == SIMPLE.

I think that's the bug, why it is that value is beyond me.

Stephen



On Fri, Apr 15, 2016 at 7:49 PM, Andy Clement <[hidden email]> wrote:
My immediate reaction is that:

ResolvedType baseType = fromType(pt.getRawType());

might be returning the generic type and not a raw type. But I’ve been trying to craft a test case based on your declarations and nothing is failing. Do you have a test case you can share that actually fails?

I recently ran in to a problem with Spring AOP and AspectJ which appeared on this mailing list in March.

I found that thread and it didn’t really come to a satisfying conclusion, so it would be good to get this sorted.

cheers,
Andy

On Apr 14, 2016, at 8:22 AM, Stephen Evanchik <[hidden email]> wrote:

Hello,

I recently ran in to a problem with Spring AOP and AspectJ which appeared on this mailing list in March. I'm not sure what is going on because I've changed very little that would obviously cause this exception. There are many Generic types in the project that could/would be processed by AspectJ why this one is throwing things off is a mystery. I believe the reason this type is causing a problem now is because the concrete class used to be hidden behind a JDK Proxy so the AspectJ type evaluation did not see the concrete class and it's generic type. The class signature in question looks like this:

public class ConcreteClass extends AbstractClass<ConcreteType>

where AbstractClass<T> is defined as:

public abstract AbstractClass<T> extends AbstractSuperClass <T, ID> implements InterfaceOne InterfaceTwo<T>


Here's the stack trace:

Caused by: java.lang.IllegalStateException: Expecting raw type, not: ConcreteClass
    at org.aspectj.weaver.TypeFactory.createParameterizedType(TypeFactory.java:34)
    at org.aspectj.weaver.reflect.JavaLangTypeToResolvedTypeConverter.fromType(JavaLangTypeToResolvedTypeConverter.java:79)
    at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.getSuperclass(Java15ReflectionBasedReferenceTypeDelegate.java:156)
    at org.aspectj.weaver.ReferenceType.getSuperclass(ReferenceType.java:987)
    at org.aspectj.weaver.JoinPointSignatureIterator.addSignaturesUpToFirstDefiningMember(JoinPointSignatureIterator.java:95)
    at org.aspectj.weaver.JoinPointSignatureIterator.<init>(JoinPointSignatureIterator.java:49)
    at org.aspectj.weaver.MemberImpl.getJoinPointSignatures(MemberImpl.java:515)
    at org.aspectj.weaver.patterns.SignaturePattern.matches(SignaturePattern.java:316)
    at org.aspectj.weaver.patterns.KindedPointcut.matchInternal(KindedPointcut.java:197)
    at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:137)
    at org.aspectj.weaver.patterns.OrPointcut.matchInternal(OrPointcut.java:56)
    at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:137)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.getShadowMatch(PointcutExpressionImpl.java:319)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.matchesExecution(PointcutExpressionImpl.java:129)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.matchesMethodExecution(PointcutExpressionImpl.java:110)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.getShadowMatch(AspectJExpressionPointcut.java:408)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.matches(AspectJExpressionPointcut.java:266)
    at org.springframework.aop.support.MethodMatchers.matches(MethodMatchers.java:92)
    at org.springframework.aop.support.MethodMatchers$IntersectionMethodMatcher.matches(MethodMatchers.java:228)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:223)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:262)
    at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:294)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:118)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:88)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:69)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:361)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:324)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:409)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.postProcessObjectFromFactoryBean(AbstractAutowireCapableBeanFactory.java:1657)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:129)


I'm confused about this code in JavaLangTypeToResolvedTypeContainer.fromType():

...
        } else if (aType instanceof ParameterizedType) {
            ParameterizedType pt = (ParameterizedType) aType;
            ResolvedType baseType = fromType(pt.getRawType());
            Type[] args = pt.getActualTypeArguments();
            ResolvedType[] resolvedArgs = fromTypes(args);
            /*
             * StringBuilder sb = new StringBuilder(); for (int i = 0; i < resolvedArgs.length; i++) {
             * sb.append(resolvedArgs[i]).append(" "); } for (int i = 0; i < resolvedArgs.length; i++) { if (resolvedArgs[i] ==
             * null) { String ss = ""; try { ss = aType.toString(); } catch (Exception e) { } throw new
             * IllegalStateException("Parameterized type problem.  basetype=" + baseType + " arguments=" + sb.toString() + " ss=" +
             * ss); } }
             */
            return TypeFactory.createParameterizedType(baseType, resolvedArgs, getWorld());

..

and then TypeFactory.createParameterizedType(...):

        ResolvedType baseType = aBaseType;
        if (!aBaseType.isGenericType()) {
            // try and find the generic type...
            if (someTypeParameters != null && someTypeParameters.length > 0) {
                if (!aBaseType.isRawType()) {
                    throw new IllegalStateException("Expecting raw type, not: " + aBaseType);
                }
                baseType = baseType.getGenericType();
                if (baseType == null) {
                    throw new IllegalStateException("Raw type does not have generic type set");
                }
            } // else if someTypeParameters is null, then the base type is allowed to be non-generic, it's an inner
        }



because I don't understand why:

               if (!aBaseType.isRawType()) {
                    throw new IllegalStateException("Expecting raw type, not: " + aBaseType);
                }

aBaseType, which is a RawType from above, is evaluating to anything other than a raw type.


Stephen
_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev



-- 
_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev



-- 



-- 
_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: aspectj 1.8.[4, 9] - java.lang.IllegalStateException: Expecting raw type, not ...

Stephen Evanchik
Hi Andy,

I think I know what the problem is and why this has been so confusing. My environment is running in OSGi which presents all sorts of ClassLoader issues as well as awkward tooling.

In this case, the problem is because the class is being imported via the OSGi Service Registry under a broadly visible interface (let's call it InterfaceA). Once the ServiceReference is obtained, Spring creates a bean in the ApplicationContext that can be post-processed. In my case the Spring AOP post-processor is attempting to parse a PointCut or JoinPoint expression and in doing so is processing the class instance of InterfaceA.

InterfaceA is visible via an Import-Package directive but its concrete class ClassA and AbstractSuperClassA are in packages not found in the bundle's Import-Package directive. At some point in the parsing process ClassA and AbstractSuperClassA requires the Class object to perform some sort of calculation. I believe the Class object can only be retrieved via:

public class ReflectionBasedReferenceTypeDelegateFactory {

    public static ReflectionBasedReferenceTypeDelegate createDelegate(ReferenceType forReferenceType, World inWorld,
            ClassLoader usingClassLoader) {
        try {
            Class c = Class.forName(forReferenceType.getName(), false, usingClassLoader);
            if (LangUtil.is15VMOrGreater()) {
                ReflectionBasedReferenceTypeDelegate rbrtd = create15Delegate(forReferenceType, c, usingClassLoader, inWorld);
                if (rbrtd != null) {
                    return rbrtd; // can be null if we didn't find the class the delegate logic loads
                }
            }
            return new ReflectionBasedReferenceTypeDelegate(c, usingClassLoader, inWorld, forReferenceType);
        } catch (ClassNotFoundException cnfEx) {
            return null;
        }
    }

The ReflectionBasedReferenceTypeDelegateFactory.createDelegate() always returns null because of a ClassNotFoundException.

This is because the usingClassLoader instance is for the bundle whose Import-Package does not import the AbstractSuperClassA's package.

The usingClassLoader instance comes from the ReflectionWorld's constructor -- I don't know where that is instantiated but I'm guessing the ClassLoader is nothing more than the Thread Context ClassLoader.

I'm currently fighting with tooling -- bnd is not forgiving and won't insert the package in to the MANIFEST.MF without first detecting some sort of reference to the package.

Stephen


On Mon, May 16, 2016 at 3:08 PM, Andy Clement <[hidden email]> wrote:
Hi,

Certainly sounds like the right area.

Although simple types get saved into the type map, if we later discover there are generic variants it should get ‘promoted’ from simple - a call to setGenericType() on ReferenceType will promote it to raw.

So if resolution (via resolve) did put a simple type in the map, why did it not get promoted to raw when the parameterized variant is dealt with? Did setGenericType not get called?

I still feel it is the use of reflection world than is contributing to the problem and things are not happening the same as they would with a bcelworld backend. We have thousands of tests for bcelworld and comparatively very few for reflection world.

Any closer to sharing a test case? When we do end up putting fixes around in this area, we will need at least one to add to the regression suite.

cheers,
Andy

On May 16, 2016, at 9:26 AM, Stephen Evanchik <[hidden email]> wrote:

Hi Andy,

I think I understand where the TypeKind SIMPLE shows up. In the following code:

        } else if (aType instanceof ParameterizedType) {
            ParameterizedType pt = (ParameterizedType) aType;
            ResolvedType baseType = fromType(pt.getRawType());

pt is correctly a ParameterizedTypeImpl whose .toString() shows the correct type package.Type<ParameterType> . The pt.getRawType() returns a Class whose .toString() yields the simple package.Type. This gets fed to:

        if (aType instanceof Class) {
            Class clazz = (Class) aType;
            String name = clazz.getName();
            /**
             * getName() can return:
             * 
             * 1. If this class object represents a reference type that is not an array type then the binary name of the class is
             * returned 2. If this class object represents a primitive type or void, then the name returned is a String equal to the
             * Java language keyword corresponding to the primitive type or void. 3. If this class object represents a class of
             * arrays, then the internal form of the name consists of the name of the element type preceded by one or more '['
             * characters representing the depth of the array nesting.
             */
            if (clazz.isArray()) {
                UnresolvedType ut = UnresolvedType.forSignature(name.replace('.', '/'));
                return getWorld().resolve(ut);
            } else {
                return getWorld().resolve(name);
            }

This is where things start to get interesting, resolve(<String>) is implemented as:

    public ResolvedType resolve(String name) {
        // trace.enter("resolve", this, new Object[] {name});
        ResolvedType ret = resolve(UnresolvedType.forName(name));
        // trace.exit("resolve", ret);
        return ret;
    }


and I believe the problem is that UnresolvedType.forName() is where the raw type information is finally and completely lost. At some point the UnresolvedType is created in TypeFactory:

        } else if (firstChar == 'L') {
            // only an issue if there is also an angle bracket
            int leftAngleBracket = signature.indexOf('<');

            if (leftAngleBracket == -1) {
                return new UnresolvedType(signature);

This is where things go wrong as the default TypeKind == SIMPLE but we're working with a type that has been erased (If I understand all of this terminology correctly).

Stephen


On Tue, May 3, 2016 at 2:40 PM, Stephen Evanchik <[hidden email]> wrote:
Hi Andy,

I recreated the class hierarchy in weaver5's test tree. I have a simple test which is trying to resolve the class using ReflectionWorld. I always see a typeKind of RAW and never simple.

I even went to the trouble of naming every class and package exactly as what is in the running program. Unfortunately, capturing what is going on in the program is difficult due to the amount of initialization that occurs just before the fatal exception. I'll try a conditional breakpoint and see if I can get that working.



Stephen

On Mon, Apr 18, 2016 at 5:41 PM, Andy Clement <[hidden email]> wrote:
Hey Stephen,

If you can share a program with me that fails I’m happy to dive into it, rather than you having to dive into working how to build a test. I was crafting tests in ReflectionWorldTest in weaver5 but nothing basic was triggering the issue, possibly because of something that happens earlier that I don’t know about. 

If you want to debug further yourself, stick a breakpoint in TypeMap.put() and look at what is happening when it puts the SIMPLE form of AbstractClass in there. Why did it build the SIMPLE form and not the raw or generic.

But as I say, I’m happy to look, but I just can’t recreate the problem.

cheers,
Andy

On Apr 18, 2016, at 11:16 AM, Stephen Evanchik <[hidden email]> wrote:

Hi Andy,

I have the AspectJ source tree pulled down and will look in to generating a test. Any pointers would be appreciated; it looks I need to modify something in weaver5's test area, is that right?

            ResolvedType baseType = fromType(pt.getRawType());

This returns Class<?> of AbstractClass (so no generics as far as I can tell). However, in TypeFactory:

                if (!aBaseType.isRawType()) {


returns false because the typeKind == SIMPLE.

I think that's the bug, why it is that value is beyond me.

Stephen



On Fri, Apr 15, 2016 at 7:49 PM, Andy Clement <[hidden email]> wrote:
My immediate reaction is that:

ResolvedType baseType = fromType(pt.getRawType());

might be returning the generic type and not a raw type. But I’ve been trying to craft a test case based on your declarations and nothing is failing. Do you have a test case you can share that actually fails?

I recently ran in to a problem with Spring AOP and AspectJ which appeared on this mailing list in March.

I found that thread and it didn’t really come to a satisfying conclusion, so it would be good to get this sorted.

cheers,
Andy

On Apr 14, 2016, at 8:22 AM, Stephen Evanchik <[hidden email]> wrote:

Hello,

I recently ran in to a problem with Spring AOP and AspectJ which appeared on this mailing list in March. I'm not sure what is going on because I've changed very little that would obviously cause this exception. There are many Generic types in the project that could/would be processed by AspectJ why this one is throwing things off is a mystery. I believe the reason this type is causing a problem now is because the concrete class used to be hidden behind a JDK Proxy so the AspectJ type evaluation did not see the concrete class and it's generic type. The class signature in question looks like this:

public class ConcreteClass extends AbstractClass<ConcreteType>

where AbstractClass<T> is defined as:

public abstract AbstractClass<T> extends AbstractSuperClass <T, ID> implements InterfaceOne InterfaceTwo<T>


Here's the stack trace:

Caused by: java.lang.IllegalStateException: Expecting raw type, not: ConcreteClass
    at org.aspectj.weaver.TypeFactory.createParameterizedType(TypeFactory.java:34)
    at org.aspectj.weaver.reflect.JavaLangTypeToResolvedTypeConverter.fromType(JavaLangTypeToResolvedTypeConverter.java:79)
    at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.getSuperclass(Java15ReflectionBasedReferenceTypeDelegate.java:156)
    at org.aspectj.weaver.ReferenceType.getSuperclass(ReferenceType.java:987)
    at org.aspectj.weaver.JoinPointSignatureIterator.addSignaturesUpToFirstDefiningMember(JoinPointSignatureIterator.java:95)
    at org.aspectj.weaver.JoinPointSignatureIterator.<init>(JoinPointSignatureIterator.java:49)
    at org.aspectj.weaver.MemberImpl.getJoinPointSignatures(MemberImpl.java:515)
    at org.aspectj.weaver.patterns.SignaturePattern.matches(SignaturePattern.java:316)
    at org.aspectj.weaver.patterns.KindedPointcut.matchInternal(KindedPointcut.java:197)
    at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:137)
    at org.aspectj.weaver.patterns.OrPointcut.matchInternal(OrPointcut.java:56)
    at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:137)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.getShadowMatch(PointcutExpressionImpl.java:319)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.matchesExecution(PointcutExpressionImpl.java:129)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.matchesMethodExecution(PointcutExpressionImpl.java:110)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.getShadowMatch(AspectJExpressionPointcut.java:408)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.matches(AspectJExpressionPointcut.java:266)
    at org.springframework.aop.support.MethodMatchers.matches(MethodMatchers.java:92)
    at org.springframework.aop.support.MethodMatchers$IntersectionMethodMatcher.matches(MethodMatchers.java:228)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:223)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:262)
    at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:294)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:118)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:88)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:69)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:361)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:324)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:409)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.postProcessObjectFromFactoryBean(AbstractAutowireCapableBeanFactory.java:1657)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:129)


I'm confused about this code in JavaLangTypeToResolvedTypeContainer.fromType():

...
        } else if (aType instanceof ParameterizedType) {
            ParameterizedType pt = (ParameterizedType) aType;
            ResolvedType baseType = fromType(pt.getRawType());
            Type[] args = pt.getActualTypeArguments();
            ResolvedType[] resolvedArgs = fromTypes(args);
            /*
             * StringBuilder sb = new StringBuilder(); for (int i = 0; i < resolvedArgs.length; i++) {
             * sb.append(resolvedArgs[i]).append(" "); } for (int i = 0; i < resolvedArgs.length; i++) { if (resolvedArgs[i] ==
             * null) { String ss = ""; try { ss = aType.toString(); } catch (Exception e) { } throw new
             * IllegalStateException("Parameterized type problem.  basetype=" + baseType + " arguments=" + sb.toString() + " ss=" +
             * ss); } }
             */
            return TypeFactory.createParameterizedType(baseType, resolvedArgs, getWorld());

..

and then TypeFactory.createParameterizedType(...):

        ResolvedType baseType = aBaseType;
        if (!aBaseType.isGenericType()) {
            // try and find the generic type...
            if (someTypeParameters != null && someTypeParameters.length > 0) {
                if (!aBaseType.isRawType()) {
                    throw new IllegalStateException("Expecting raw type, not: " + aBaseType);
                }
                baseType = baseType.getGenericType();
                if (baseType == null) {
                    throw new IllegalStateException("Raw type does not have generic type set");
                }
            } // else if someTypeParameters is null, then the base type is allowed to be non-generic, it's an inner
        }



because I don't understand why:

               if (!aBaseType.isRawType()) {
                    throw new IllegalStateException("Expecting raw type, not: " + aBaseType);
                }

aBaseType, which is a RawType from above, is evaluating to anything other than a raw type.


Stephen
_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev



-- 
_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev



-- 



-- 
_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev



--

_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: aspectj 1.8.[4, 9] - java.lang.IllegalStateException: Expecting raw type, not ...

Andy Clement
I didn’t realize OSGi was in the mix, fun fun fun, yep that could certainly exercise things differently. I suppose is might be possible to set up a small class loader hierarchy with the visibility rules similar to what OSGi is doing and then exercising AspectJ through that (in the way Spring will be exercising it) in order to recreate.

cheers,
Andy

On May 17, 2016, at 9:54 AM, Stephen Evanchik <[hidden email]> wrote:

Hi Andy,

I think I know what the problem is and why this has been so confusing. My environment is running in OSGi which presents all sorts of ClassLoader issues as well as awkward tooling.

In this case, the problem is because the class is being imported via the OSGi Service Registry under a broadly visible interface (let's call it InterfaceA). Once the ServiceReference is obtained, Spring creates a bean in the ApplicationContext that can be post-processed. In my case the Spring AOP post-processor is attempting to parse a PointCut or JoinPoint expression and in doing so is processing the class instance of InterfaceA.

InterfaceA is visible via an Import-Package directive but its concrete class ClassA and AbstractSuperClassA are in packages not found in the bundle's Import-Package directive. At some point in the parsing process ClassA and AbstractSuperClassA requires the Class object to perform some sort of calculation. I believe the Class object can only be retrieved via:

public class ReflectionBasedReferenceTypeDelegateFactory {

    public static ReflectionBasedReferenceTypeDelegate createDelegate(ReferenceType forReferenceType, World inWorld,
            ClassLoader usingClassLoader) {
        try {
            Class c = Class.forName(forReferenceType.getName(), false, usingClassLoader);
            if (LangUtil.is15VMOrGreater()) {
                ReflectionBasedReferenceTypeDelegate rbrtd = create15Delegate(forReferenceType, c, usingClassLoader, inWorld);
                if (rbrtd != null) {
                    return rbrtd; // can be null if we didn't find the class the delegate logic loads
                }
            }
            return new ReflectionBasedReferenceTypeDelegate(c, usingClassLoader, inWorld, forReferenceType);
        } catch (ClassNotFoundException cnfEx) {
            return null;
        }
    }

The ReflectionBasedReferenceTypeDelegateFactory.createDelegate() always returns null because of a ClassNotFoundException.

This is because the usingClassLoader instance is for the bundle whose Import-Package does not import the AbstractSuperClassA's package.

The usingClassLoader instance comes from the ReflectionWorld's constructor -- I don't know where that is instantiated but I'm guessing the ClassLoader is nothing more than the Thread Context ClassLoader.

I'm currently fighting with tooling -- bnd is not forgiving and won't insert the package in to the MANIFEST.MF without first detecting some sort of reference to the package.

Stephen


On Mon, May 16, 2016 at 3:08 PM, Andy Clement <[hidden email]> wrote:
Hi,

Certainly sounds like the right area.

Although simple types get saved into the type map, if we later discover there are generic variants it should get ‘promoted’ from simple - a call to setGenericType() on ReferenceType will promote it to raw.

So if resolution (via resolve) did put a simple type in the map, why did it not get promoted to raw when the parameterized variant is dealt with? Did setGenericType not get called?

I still feel it is the use of reflection world than is contributing to the problem and things are not happening the same as they would with a bcelworld backend. We have thousands of tests for bcelworld and comparatively very few for reflection world.

Any closer to sharing a test case? When we do end up putting fixes around in this area, we will need at least one to add to the regression suite.

cheers,
Andy

On May 16, 2016, at 9:26 AM, Stephen Evanchik <[hidden email]> wrote:

Hi Andy,

I think I understand where the TypeKind SIMPLE shows up. In the following code:

        } else if (aType instanceof ParameterizedType) {
            ParameterizedType pt = (ParameterizedType) aType;
            ResolvedType baseType = fromType(pt.getRawType());

pt is correctly a ParameterizedTypeImpl whose .toString() shows the correct type package.Type<ParameterType> . The pt.getRawType() returns a Class whose .toString() yields the simple package.Type. This gets fed to:

        if (aType instanceof Class) {
            Class clazz = (Class) aType;
            String name = clazz.getName();
            /**
             * getName() can return:
             * 
             * 1. If this class object represents a reference type that is not an array type then the binary name of the class is
             * returned 2. If this class object represents a primitive type or void, then the name returned is a String equal to the
             * Java language keyword corresponding to the primitive type or void. 3. If this class object represents a class of
             * arrays, then the internal form of the name consists of the name of the element type preceded by one or more '['
             * characters representing the depth of the array nesting.
             */
            if (clazz.isArray()) {
                UnresolvedType ut = UnresolvedType.forSignature(name.replace('.', '/'));
                return getWorld().resolve(ut);
            } else {
                return getWorld().resolve(name);
            }

This is where things start to get interesting, resolve(<String>) is implemented as:

    public ResolvedType resolve(String name) {
        // trace.enter("resolve", this, new Object[] {name});
        ResolvedType ret = resolve(UnresolvedType.forName(name));
        // trace.exit("resolve", ret);
        return ret;
    }


and I believe the problem is that UnresolvedType.forName() is where the raw type information is finally and completely lost. At some point the UnresolvedType is created in TypeFactory:

        } else if (firstChar == 'L') {
            // only an issue if there is also an angle bracket
            int leftAngleBracket = signature.indexOf('<');

            if (leftAngleBracket == -1) {
                return new UnresolvedType(signature);

This is where things go wrong as the default TypeKind == SIMPLE but we're working with a type that has been erased (If I understand all of this terminology correctly).

Stephen


On Tue, May 3, 2016 at 2:40 PM, Stephen Evanchik <[hidden email]> wrote:
Hi Andy,

I recreated the class hierarchy in weaver5's test tree. I have a simple test which is trying to resolve the class using ReflectionWorld. I always see a typeKind of RAW and never simple.

I even went to the trouble of naming every class and package exactly as what is in the running program. Unfortunately, capturing what is going on in the program is difficult due to the amount of initialization that occurs just before the fatal exception. I'll try a conditional breakpoint and see if I can get that working.



Stephen

On Mon, Apr 18, 2016 at 5:41 PM, Andy Clement <[hidden email]> wrote:
Hey Stephen,

If you can share a program with me that fails I’m happy to dive into it, rather than you having to dive into working how to build a test. I was crafting tests in ReflectionWorldTest in weaver5 but nothing basic was triggering the issue, possibly because of something that happens earlier that I don’t know about. 

If you want to debug further yourself, stick a breakpoint in TypeMap.put() and look at what is happening when it puts the SIMPLE form of AbstractClass in there. Why did it build the SIMPLE form and not the raw or generic.

But as I say, I’m happy to look, but I just can’t recreate the problem.

cheers,
Andy

On Apr 18, 2016, at 11:16 AM, Stephen Evanchik <[hidden email]> wrote:

Hi Andy,

I have the AspectJ source tree pulled down and will look in to generating a test. Any pointers would be appreciated; it looks I need to modify something in weaver5's test area, is that right?

            ResolvedType baseType = fromType(pt.getRawType());

This returns Class<?> of AbstractClass (so no generics as far as I can tell). However, in TypeFactory:

                if (!aBaseType.isRawType()) {


returns false because the typeKind == SIMPLE.

I think that's the bug, why it is that value is beyond me.

Stephen



On Fri, Apr 15, 2016 at 7:49 PM, Andy Clement <[hidden email]> wrote:
My immediate reaction is that:

ResolvedType baseType = fromType(pt.getRawType());

might be returning the generic type and not a raw type. But I’ve been trying to craft a test case based on your declarations and nothing is failing. Do you have a test case you can share that actually fails?

I recently ran in to a problem with Spring AOP and AspectJ which appeared on this mailing list in March.

I found that thread and it didn’t really come to a satisfying conclusion, so it would be good to get this sorted.

cheers,
Andy

On Apr 14, 2016, at 8:22 AM, Stephen Evanchik <[hidden email]> wrote:

Hello,

I recently ran in to a problem with Spring AOP and AspectJ which appeared on this mailing list in March. I'm not sure what is going on because I've changed very little that would obviously cause this exception. There are many Generic types in the project that could/would be processed by AspectJ why this one is throwing things off is a mystery. I believe the reason this type is causing a problem now is because the concrete class used to be hidden behind a JDK Proxy so the AspectJ type evaluation did not see the concrete class and it's generic type. The class signature in question looks like this:

public class ConcreteClass extends AbstractClass<ConcreteType>

where AbstractClass<T> is defined as:

public abstract AbstractClass<T> extends AbstractSuperClass <T, ID> implements InterfaceOne InterfaceTwo<T>


Here's the stack trace:

Caused by: java.lang.IllegalStateException: Expecting raw type, not: ConcreteClass
    at org.aspectj.weaver.TypeFactory.createParameterizedType(TypeFactory.java:34)
    at org.aspectj.weaver.reflect.JavaLangTypeToResolvedTypeConverter.fromType(JavaLangTypeToResolvedTypeConverter.java:79)
    at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.getSuperclass(Java15ReflectionBasedReferenceTypeDelegate.java:156)
    at org.aspectj.weaver.ReferenceType.getSuperclass(ReferenceType.java:987)
    at org.aspectj.weaver.JoinPointSignatureIterator.addSignaturesUpToFirstDefiningMember(JoinPointSignatureIterator.java:95)
    at org.aspectj.weaver.JoinPointSignatureIterator.<init>(JoinPointSignatureIterator.java:49)
    at org.aspectj.weaver.MemberImpl.getJoinPointSignatures(MemberImpl.java:515)
    at org.aspectj.weaver.patterns.SignaturePattern.matches(SignaturePattern.java:316)
    at org.aspectj.weaver.patterns.KindedPointcut.matchInternal(KindedPointcut.java:197)
    at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:137)
    at org.aspectj.weaver.patterns.OrPointcut.matchInternal(OrPointcut.java:56)
    at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:137)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.getShadowMatch(PointcutExpressionImpl.java:319)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.matchesExecution(PointcutExpressionImpl.java:129)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.matchesMethodExecution(PointcutExpressionImpl.java:110)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.getShadowMatch(AspectJExpressionPointcut.java:408)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.matches(AspectJExpressionPointcut.java:266)
    at org.springframework.aop.support.MethodMatchers.matches(MethodMatchers.java:92)
    at org.springframework.aop.support.MethodMatchers$IntersectionMethodMatcher.matches(MethodMatchers.java:228)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:223)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:262)
    at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:294)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:118)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:88)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:69)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:361)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:324)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:409)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.postProcessObjectFromFactoryBean(AbstractAutowireCapableBeanFactory.java:1657)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:129)


I'm confused about this code in JavaLangTypeToResolvedTypeContainer.fromType():

...
        } else if (aType instanceof ParameterizedType) {
            ParameterizedType pt = (ParameterizedType) aType;
            ResolvedType baseType = fromType(pt.getRawType());
            Type[] args = pt.getActualTypeArguments();
            ResolvedType[] resolvedArgs = fromTypes(args);
            /*
             * StringBuilder sb = new StringBuilder(); for (int i = 0; i < resolvedArgs.length; i++) {
             * sb.append(resolvedArgs[i]).append(" "); } for (int i = 0; i < resolvedArgs.length; i++) { if (resolvedArgs[i] ==
             * null) { String ss = ""; try { ss = aType.toString(); } catch (Exception e) { } throw new
             * IllegalStateException("Parameterized type problem.  basetype=" + baseType + " arguments=" + sb.toString() + " ss=" +
             * ss); } }
             */
            return TypeFactory.createParameterizedType(baseType, resolvedArgs, getWorld());

..

and then TypeFactory.createParameterizedType(...):

        ResolvedType baseType = aBaseType;
        if (!aBaseType.isGenericType()) {
            // try and find the generic type...
            if (someTypeParameters != null && someTypeParameters.length > 0) {
                if (!aBaseType.isRawType()) {
                    throw new IllegalStateException("Expecting raw type, not: " + aBaseType);
                }
                baseType = baseType.getGenericType();
                if (baseType == null) {
                    throw new IllegalStateException("Raw type does not have generic type set");
                }
            } // else if someTypeParameters is null, then the base type is allowed to be non-generic, it's an inner
        }



because I don't understand why:

               if (!aBaseType.isRawType()) {
                    throw new IllegalStateException("Expecting raw type, not: " + aBaseType);
                }

aBaseType, which is a RawType from above, is evaluating to anything other than a raw type.


Stephen
_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev



-- 
_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev



-- 



-- 
_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev



--
_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


_______________________________________________
aspectj-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-dev
Loading...