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

Iterating over a list of enums generated by Qute Namespace Extensions no longer works #21008

Closed
wjglerum opened this issue Oct 26, 2021 · 6 comments · Fixed by #21028
Closed
Assignees
Labels
area/qute The template engine kind/bug Something isn't working
Milestone

Comments

@wjglerum
Copy link
Contributor

wjglerum commented Oct 26, 2021

Describe the bug

We leverage Qute Namespace extensions to populate a list or dropdown with values from an enum. See https://quarkus.io/version/main/guides/qute-reference#namespace_extension_methods

public enum State {
    OPEN("Open"), CLOSED("Closed");

    private final String displayName;

    State(String displayName) {
        this.displayName = displayName;
    }

    public String getDisplayName() {
        return displayName;
    }
}
@TemplateExtension(namespace = "domain")
public static class DomainExtensions {

    static Set<State> states() {
        return EnumSet.allOf(State.class);
    }
}
<ul>
    {#for state in domain:states}
        <li>{state.displayName}</li>
    {/for}
</ul>

However this now results in an exception, also when we use checked templates.

[1] Incorrect expression found: {state.displayName}
	- property/method [displayName] not found on class [java.util.Set<nl.wjglerum.SomePage$State>] nor handled by an extension method
	- at page.qute.html:31
	at io.quarkus.qute.deployment.QuteProcessor.processTemplateErrors(QuteProcessor.java:186)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:887)
	at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
	at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
	at java.base/java.lang.Thread.run(Thread.java:829)
	at org.jboss.threads.JBossThread.run(JBossThread.java:501)
	Suppressed: io.quarkus.qute.TemplateException: Incorrect expression found: {state.displayName}
	- property/method [displayName] not found on class [java.util.Set<nl.wjglerum.SomePage$State>] nor handled by an extension method
	- at page.qute.html:31
		at io.quarkus.qute.deployment.QuteProcessor.processTemplateErrors(QuteProcessor.java:166)
		... 11 more

It does work correctly when you just want to render the enums, but as soon as you call a property from the enum it fails. It looks like Qute incorrectly tries to find this (virtual) method on the Set or List instance instead of the enum in the collection.

This used to work up until version 2.4.0.CR1 but just failed on the latest snapshot build from the main branch.

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

Sample project:
quarkus-qute-enum.zip

@wjglerum wjglerum added the kind/bug Something isn't working label Oct 26, 2021
@quarkus-bot quarkus-bot bot added the area/qute The template engine label Oct 26, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Oct 26, 2021

/cc @mkouba

@mkouba mkouba self-assigned this Oct 26, 2021
@wjglerum
Copy link
Contributor Author

Also seems to fail with 2.4.0.Final

@mkouba
Copy link
Contributor

mkouba commented Oct 26, 2021

Hi @wjglerum, I'll take a closer look tomorrow. But I believe that previously those expressions were not validated at all (we did not validate namespace expressions until recently). This PR is related.

@wjglerum
Copy link
Contributor Author

Hi @wjglerum, I'll take a closer look tomorrow. But I believe that previously those expressions were not validated at all (we did not validate namespace expressions until recently). This PR is related.

Thanks for the update 👍

@mkouba
Copy link
Contributor

mkouba commented Oct 27, 2021

@wjglerum #21028 should fix the problem. It would be great if you could give it a try..

@wjglerum
Copy link
Contributor Author

@wjglerum #21028 should fix the problem. It would be great if you could give it a try..

Just checked it out locally and seems to work again, thanks again for the quick response!

@quarkus-bot quarkus-bot bot added this to the 2.5 - main milestone Oct 27, 2021
@gsmet gsmet modified the milestones: 2.5 - main, 2.4.1.Final Nov 2, 2021
gsmet pushed a commit to gsmet/quarkus that referenced this issue Nov 2, 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

Successfully merging a pull request may close this issue.

3 participants