Bauke Scholtz created MYFACES-4783:
--------------------------------------

             Summary: UISelectOne.processValidators throws NullPointerException 
for a grouped radio next to a UISelectOne without a group
                 Key: MYFACES-4783
                 URL: https://issues.apache.org/jira/browse/MYFACES-4783
             Project: MyFaces Core
          Issue Type: Bug
    Affects Versions: 4.1.5
            Reporter: Bauke Scholtz


A form with an `h:selectOneRadio` with a `group`, and also an `h:selectOneMenu` 
or `h:selectOneListbox` without a `group`, fails during PROCESS_VALIDATIONS 
when the grouped radio is submitted without a value:

```
java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because 
the return value of "jakarta.faces.component.UISelectOne.getGroup()" is null
```

Reproducer:

```xhtml
<h:form>
    <h:selectOneRadio group="g1" value="#{bean.choice}">
        <f:selectItems value="#{bean.items}"/>
    </h:selectOneRadio>
    <h:selectOneMenu value="#{bean.other}">
        <f:selectItems value="#{bean.items}"/>
    </h:selectOneMenu>
    <h:commandButton value="Submit"/>
</h:form>
```

Submit the form without selecting a radio.

Cause: `UISelectOne.processValidators()` visits the form, and the visit 
callback calls `((UISelectOne) target).getGroup().equals(group)` for every 
`UISelectOne` it finds. `getGroup()` is `null` for a `UISelectOne` without a 
group. The same call is in the visit callback of 
`getSelectItemCollectionForGroup()`. Both are in 
`api/src/main/java/jakarta/faces/component/UISelectOne.java` on main, 4.1.x and 
4.0.x.

Fix: `group.equals(((UISelectOne) target).getGroup())` in both places. `group` 
is not null there, as both visits only run when it is not empty.

History:
- a6668bd46 (2017-11-17, MYFACES-4169) added the visit with this comparison.
- 7f536b4db (2023-02-08, MYFACES-4551) added the second visit with the same 
comparison.

Found while running a Mojarra benchmark page, which renders every HTML tag with 
every attribute, on MyFaces 4.1.5-SNAPSHOT.

🤖 Generated with Claude Opus 5.5



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to