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

Qute fails to resolve properties on enum classes only when native compiled #20421

Closed
jayv opened this issue Sep 27, 2021 · 2 comments
Closed
Labels
area/qute The template engine kind/bug Something isn't working

Comments

@jayv
Copy link

jayv commented Sep 27, 2021

Describe the bug

Templates render NOT_FOUND in native mode (works fine on JVM) for enum classes when attempting to access a member field of getter of the enum class.

Expected behavior

Render the member field or method both in JVM as in native mode.

Actual behavior

Qute resolves the property in JVM mode just fine but resolves as NOT_FOUND when compiled to native. Current workaround is to override toString() which is the only way to render an enum it seems.

How to Reproduce?

data class AuthenticatedUser( 
    val roles: Set<Role>
)

enum class Role(val group: String) {
   
    BASIC("SomeBasicGroup"),
    ADMIN("AdminGroup);

    // this is a workaround
    override fun toString(): String { 
        return group
    }
}

            {#for role in user.roles.orEmpty}
                <li>{role.group}</li> 
            {/for}

The above renders NOT_FOUND when native compiled, however when {role} is used it works, so toString() can be called. Adding an other method or getter also results in NOT_FOUND again only when native compiled.

Output of uname -a or ver

quay.io/quarkus/centos-quarkus-maven:21.0-java11

GraalVM version (if different from Java)

quay.io/quarkus/centos-quarkus-maven:21.0-java11

Quarkus version or git rev

1.13.2.Final

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

mvn 3.6.2

@jayv jayv added the kind/bug Something isn't working label Sep 27, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Sep 27, 2021

/cc @mkouba

@quarkus-bot quarkus-bot bot added the area/qute The template engine label Sep 27, 2021
@mkouba
Copy link
Contributor

mkouba commented Sep 29, 2021

Hi @jayv, this is expected. In the JVM a fallback reflection value resolver is used, i.e. enum constants are read as regular fields. Of course, this does not work for native. There are several ways how to solve the problem for the native image:

  1. Make use of type-safe templates or type-safe expressions (preferred); this way a specialized value resolver is generated automatically
  2. Annotate the enum class with @TemplateData so that a specialized value resolver is generated
  3. Annotate the enum class with @io.quarkus.runtime.annotations.RegisterForReflection to make the reflection value resolver work

mkouba added a commit to mkouba/quarkus that referenced this issue Sep 30, 2021
@mkouba mkouba closed this as completed Sep 30, 2021
gsmet pushed a commit to gsmet/quarkus that referenced this issue Oct 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/qute The template engine kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants