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

RESTEasy Reactive: issues with char parameter #24541

Closed
FroMage opened this issue Mar 24, 2022 · 4 comments · Fixed by #24549
Closed

RESTEasy Reactive: issues with char parameter #24541

FroMage opened this issue Mar 24, 2022 · 4 comments · Fixed by #24549
Labels
area/rest kind/bug Something isn't working
Milestone

Comments

@FroMage
Copy link
Member

FroMage commented Mar 24, 2022

Describe the bug

When I have an endpoint with a char parameter, native-image doesn't work:

Error: com.oracle.graal.pointsto.constraints.UnresolvedElementException: Discovered unresolved method during parsing: java.lang.Character.valueOf(java.lang.String). To diagnose the issue you can use the --allow-incomplete-classpath option. The missing method is then reported at run time when it is accessed the first time.
Trace: 
	at parsing io.quarkus.generated.char$quarkusrestparamConverter$.convert(Unknown Source)
Call path from entry point to io.quarkus.generated.char$quarkusrestparamConverter$.convert(Object): 
	at io.quarkus.generated.char$quarkusrestparamConverter$.convert(Unknown Source)
	at org.jboss.resteasy.reactive.server.core.parameters.converters.RuntimeResolvedConverter.convert(RuntimeResolvedConverter.java:23)
	at org.jboss.resteasy.reactive.server.handlers.ParameterHandler.handleResult(ParameterHandler.java:92)
	at org.jboss.resteasy.reactive.server.handlers.ParameterHandler.handle(ParameterHandler.java:55)
	at org.jboss.resteasy.reactive.server.handlers.ParameterHandler.handle(ParameterHandler.java:15)
	at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:141)
	at java.lang.Thread.run(Thread.java:829)
	at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:597)
	at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:194)
	at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)

This is due to https://github.com/quarkusio/quarkus/blob/main/independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor/generation/converters/GeneratedConverterIndexerExtension.java because Character.valueOf(String) doesn't exist.

If you don't compile natively, endpoints with a char parameter return a 404 because some converter is needed:

package io.quarkiverse.renarde.util;

import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.ws.rs.ext.ParamConverter;
import javax.ws.rs.ext.ParamConverterProvider;
import javax.ws.rs.ext.Provider;

@Provider
public class MyParamConverters implements ParamConverterProvider {

    public static class CharacterParamConverter implements ParamConverter<Character> {

        @Override
        public Character fromString(String value) {
            if (StringUtils.isEmpty(value))
                return null;
            if (value.length() != 1)
                throw new RuntimeException("Invalid character: " + value);
            return value.charAt(0);
        }

        @Override
        public String toString(Character value) {
            if (value == null)
                return null;
            return value.toString();
        }
    }

    @Override
    public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {
        if (rawType == Character.class || rawType == char.class)
            return (ParamConverter<T>) new CharacterParamConverter();
        return null;
    }

}

I don't think this converter should be required, so it's probably a bug.

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

@FroMage FroMage added the kind/bug Something isn't working label Mar 24, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Mar 24, 2022

/cc @geoand, @stuartwdouglas

@geoand
Copy link
Contributor

geoand commented Mar 24, 2022

I'll have a look, thanks

@gastaldi
Copy link
Contributor

gastaldi commented Mar 24, 2022

Here is a test case that reproduces the issue:

package org.jboss.resteasy.reactive.server.vertx.test.simple;

import org.jboss.resteasy.reactive.server.vertx.test.framework.ResteasyReactiveUnitTest;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;

import static io.restassured.RestAssured.when;
import static org.hamcrest.Matchers.equalTo;

public class ParamConverterTest {

    @RegisterExtension
    static ResteasyReactiveUnitTest test = new ResteasyReactiveUnitTest()
            .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
                    .addClasses(EchoResource.class));

    @Test
    public void charParam() {
        when().get("/echo/character?param=a")
                .then()
                    .statusCode(200)
                    .body(equalTo("a"));
    }

    @Path("echo")
    public static class EchoResource {

        @Path("character")
        @GET
        public String echoChar(@QueryParam("param") char param) {
            return "" + param;
        }
    }

}

@geoand
Copy link
Contributor

geoand commented Mar 25, 2022

char as a type does not make a tremendous amount of sense, but I opened #24549 in any case

geoand added a commit to geoand/quarkus that referenced this issue Mar 28, 2022
FroMage added a commit that referenced this issue Mar 29, 2022
Properly handle char and Character parameter types in JAX-RS methods
@quarkus-bot quarkus-bot bot added this to the 2.9 - main milestone Mar 29, 2022
@gsmet gsmet modified the milestones: 2.9 - main, 2.8.0.Final Mar 29, 2022
gsmet pushed a commit to gsmet/quarkus that referenced this issue Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/rest kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants