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

Invocation of static generic method of generic class causes "Illegal type in constant pool" #46

Open
BladeWise opened this issue Feb 14, 2022 · 2 comments

Comments

@BladeWise
Copy link

Trying to invoke the static generic method

Map.<K,V>of(K k1, V v1, K k2, V v2)

produces an "Illegal type in constant pool" error during the lambda class generation.

Below the test case I am using:

    @Test
    void canInvokeGenericStaticMethodOfGenericClass() {
        final var interfaceType = Type.of(Supplier.class).makeGenericType(Types.Map.makeGenericType(Types.String, Types.Integer));
        // Map.of(K k1, V v1, K k2, V v2)
        final var mapOfMethod =
            Types.Map.getMethod("of", Types.Object, Types.Object, Types.Object, Types.Object).makeGenericMethod(Types.String, Types.Integer);
        final var invoke =
            Expression.call(
                mapOfMethod,
                new ExpressionList<>(Expression.constant("k1"), Expression.constant(22), Expression.constant("k2"), Expression.constant(109))
        );
        final var lambda = Expression.lambda(interfaceType, invoke);
        //noinspection unchecked
        final var delegate = (Supplier<Map<String, Integer>>) lambda.compile();
        final var map = delegate.get();
        assertNotNull(map);
        assertEquals(map.get("key2"), 109);
    }

Attached the generated class (zipped).
lambda_mapOf.zip

@mstrobel
Copy link
Owner

I suspect this is due to Procyon emitting classes in Java 5 format, which doesn't support static interface methods. Emitting newer classfiles is, unfortunately, quite an undertaking.

@BladeWise
Copy link
Author

Have you considered migrating the runtime code generation part to ASM, or maybe make the code generation classes pluggable, so that it is possible to provide a different implementation of TypeBuilder (or emitter)?

I use Procyon mainly for the reflection and expressions features (which are great), the runtime code generation is the cherry on top, but I wouldn't mind if it was delegated to an external library.

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

No branches or pull requests

2 participants