Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxetta can't handle generic array as return value. #418

Closed
tlxtellef opened this issue Jul 27, 2017 · 1 comment
Closed

Proxetta can't handle generic array as return value. #418

tlxtellef opened this issue Jul 27, 2017 · 1 comment
Assignees
Milestone

Comments

@tlxtellef
Copy link

tlxtellef commented Jul 27, 2017

Jodd version: 3.8.6
Java version: Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
OS: macOS Sierra 10.12.5

How to reproduce:

package jodd.proxetta;

import jodd.proxetta.advice.DelegateAdvice;
import jodd.proxetta.impl.ProxyProxetta;
import jodd.proxetta.impl.ProxyProxettaBuilder;
import org.junit.Test;

public class GenericsArrayTest {

    public static class Foo<Stuff> {
        public Stuff[] getArray() {
            return (Stuff[]) new Object[0];
        }

        public <Thingy> Thingy[] getArrayStatic() {
            return (Thingy[]) new Object[0];
        }
    }

    @Test
    public void testClassesWithGenericArraysAsReturnValueProxy() {
        try {
            ProxyAspect aspect = new ProxyAspect(DelegateAdvice.class);
            ProxyProxetta proxetta = ProxyProxetta.withAspects(aspect);
            ProxyProxettaBuilder builder = proxetta.builder(Foo.class);
            builder.newInstance();
        } catch (Exception e) {
            throw new AssertionError(e);
        }
    }
}

Result:

java.lang.IllegalArgumentException: Invalid base type: Stuff
	at jodd.asm.AsmUtil.typedesc2ClassName(AsmUtil.java:123)
	at jodd.proxetta.asm.ProxettaAsmUtil.castToReturnType(ProxettaAsmUtil.java:549)
	at jodd.proxetta.asm.ProxettaMethodBuilder$1$1.visitMethodInsn(ProxettaMethodBuilder.java:375)
	at jodd.asm5.ClassReader.readCode(ClassReader.java:1429)
	at jodd.asm5.ClassReader.readMethod(ClassReader.java:1017)
	at jodd.asm5.ClassReader.accept(ClassReader.java:693)
	at jodd.asm5.ClassReader.accept(ClassReader.java:506)
	at jodd.proxetta.asm.ProxettaMethodBuilder.createProxyMethod(ProxettaMethodBuilder.java:185)
	at jodd.proxetta.asm.ProxettaMethodBuilder.visitEnd(ProxettaMethodBuilder.java:103)
	at jodd.asm5.ClassReader.readMethod(ClassReader.java:1021)
	at jodd.asm5.ClassReader.accept(ClassReader.java:693)
	at jodd.asm5.ClassReader.accept(ClassReader.java:506)
	at jodd.proxetta.impl.ProxyProxettaBuilder.process(ProxyProxettaBuilder.java:76)
	at jodd.proxetta.ProxettaBuilder.process(ProxettaBuilder.java:220)
	at jodd.proxetta.ProxettaBuilder.define(ProxettaBuilder.java:255)
	at jodd.proxetta.ProxettaBuilder.newInstance(ProxettaBuilder.java:306)
	at jodd.proxetta.GenericsArrayTest.testClassesWithGenericArraysAsReturnValueProxy(GenericsArrayTest.java:51)
	... 22 more

It will complain about "Thingy" instead if the first method is removed.

@igr igr self-assigned this Jul 27, 2017
@igr igr modified the milestone: v3.8.7 Aug 28, 2017
@igr
Copy link
Member

igr commented Aug 30, 2017

@tttellef thanx for notifying. Just wanted to let you know I started working on it.

The fix should not be too hard, but I want to write some testcases as many things are going on

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants