Skip to content

Fix default name evaluation for CDI beans#9350

Merged
matthiasblaesing merged 1 commit intoapache:masterfrom
NicolaIsotta:cdi-default-bean-name
Apr 24, 2026
Merged

Fix default name evaluation for CDI beans#9350
matthiasblaesing merged 1 commit intoapache:masterfrom
NicolaIsotta:cdi-default-bean-name

Conversation

@NicolaIsotta
Copy link
Copy Markdown
Contributor

@NicolaIsotta NicolaIsotta commented Apr 17, 2026

This PR fixes the evaluation of the default name for CDI beans to strictly align with the CDI specifications.

Quoting CDI 1.1 specs:

The default name for a managed bean is the unqualified class name of the bean class, after converting the first character to lower case.
For example, if the bean class is named ProductList, the default bean name is productList.

Subsequent specifications all maintain the exact same text. Here is the latest: Jakarta EE CDI 4.1.

Historical Notes

I'm not exactly sure why the behavior was originally changed. My guess is that some implementations weren't perfectly aligned with the specifications at the time. For historical context on the deviation, see:

NB: this currently targets master, but it would be nice to have this in NB30

@NicolaIsotta NicolaIsotta marked this pull request as draft April 17, 2026 15:15
according to the specs, the first char must always be lowercased
@NicolaIsotta NicolaIsotta force-pushed the cdi-default-bean-name branch from 490471f to c0f9db6 Compare April 17, 2026 15:24
@NicolaIsotta NicolaIsotta marked this pull request as ready for review April 17, 2026 15:25
@mbien mbien added Java EE/Jakarta EE [ci] enable enterprise job enterprise [ci] enable enterprise job ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) labels Apr 17, 2026
@apache apache locked and limited conversation to collaborators Apr 17, 2026
@apache apache unlocked this conversation Apr 17, 2026
@matthiasblaesing
Copy link
Copy Markdown
Contributor

This looks sane to me. From a quick read I think the authors of the special casing from https://bz.apache.org/netbeans/show_bug.cgi?id=249438 have mixed up the managed bean specification and the java beans specification.

At least CDI 1.1 and JSF 2.3 agree on the format.

Copy link
Copy Markdown
Contributor

@matthiasblaesing matthiasblaesing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only eyeballed this, but makes sense.

@NicolaIsotta how did you test this?

@NicolaIsotta
Copy link
Copy Markdown
Contributor Author

NicolaIsotta commented Apr 20, 2026

I discovered the issue because the web.beans module is called from the EL module for code completion, eg. in jsf pages.
Suppose you have a bean like this (the first 2 chars must be uppercase):

@Named
@RequestScoped
public class JBean {
    
    private String value = "value";

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
}

In the xhtml, Netbeans will suggest this:
image
While it's actually available as #{jBean} (as per the CDI spec), can be simply verified by putting this in the xhtml:

\#{JBean.value}= #{JBean.value}<br/>
\#{jBean.value}= #{jBean.value}

The output is this:
image
I do have a runnable jetty project if needed.

@ebarboni ebarboni added this to the NB31 milestone Apr 23, 2026
@matthiasblaesing
Copy link
Copy Markdown
Contributor

@NicolaIsotta thanks for your explanation. Indeed I just wanted to ensure that proper testing happened.

You'd like to get this into NB30 and there might be an option for that. For that please rebase your PR onto the delivery branch (ensure that only your single commit is moved!). After that update this PR and change the target branch for the PR to delivery.

@ebarboni you set milestone to NB31 - would it be ok to still move this to NB30, if Nicola makes the changes outlined in the previous paragraph? The current behavior is indeed broken and the new behavior is correct to my understanding of the JSF and CDI specifications. I tested this PR and it does the right thing.

@NicolaIsotta
Copy link
Copy Markdown
Contributor Author

We used the easy workaround (setting the value on the @Named annotation) so the fix is no longer "urgent" on my side.

@matthiasblaesing matthiasblaesing merged commit f503436 into apache:master Apr 24, 2026
29 checks passed
@matthiasblaesing
Copy link
Copy Markdown
Contributor

@NicolaIsotta thank you.
@ebarboni ignore my previous message please, it became obsolete.

@ebarboni
Copy link
Copy Markdown
Contributor

for the record. , PR was not based on master at the cut for RC2 so I changed the milestone. Always possible to change too late now

@NicolaIsotta NicolaIsotta deleted the cdi-default-bean-name branch May 3, 2026 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) enterprise [ci] enable enterprise job Java EE/Jakarta EE [ci] enable enterprise job

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants