| Summary: | TypeHelperImpl.resolveEnumConstant() needs to use Enum.name() to resolve the constant | ||||||
|---|---|---|---|---|---|---|---|
| Product: | z_Archived | Reporter: | Pascal Filion <pascal.filion> | ||||
| Component: | Eclipselink | Assignee: | Tom Ware <tom.ware> | ||||
| Status: | CLOSED FIXED | QA Contact: | |||||
| Severity: | normal | ||||||
| Priority: | P3 | CC: | eclipselink.orm-inbox, nikita.zinoviev, tom.ware | ||||
| Version: | unspecified | Flags: | tom.ware:
iplog+
|
||||
| Target Milestone: | --- | ||||||
| Hardware: | PC | ||||||
| OS: | Windows 7 | ||||||
| Whiteboard: | submitted_patch | ||||||
| Attachments: |
|
||||||
Correction, the updated for loop is:
for (int i = 0; i < constants.length; i++) {
Enum<?> enumConstant = (Enum<?>) constants[i];
if (enumConstant.name().equals(constant)) {
return enumConstant;
}
}
*** Bug 332094 has been marked as a duplicate of this bug. *** Created attachment 185667 [details]
Patch with test
Checked-in community submitted fix and added test case Reviewed by: Tom Ware - reviewed community-submitted fix Added test to JUnitJPQLSimpleTestSuite Tested with JPA and Core LRG The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink |
Build Identifier: 2.2.0.v20101201-r8590 Enum.toString() should not be used in TypeHelperImpl.resolveEnumConstant() because it can result in not finding the constant. The objects need to be type casted to Enum<?> and then name() should be used. The code would become: for (int i = 0; i < constants.length; i++) { Enum<?> enumConstant = (Enum<?) enumConstant; if (enumConstant.name().equals(constants[i])) { return constants[i]; } } A user could have an enum like this: public enum Color { RED("1"), BLUE("2"); String color; Color(String color) { this.color = color; } public String toString() { return color; } } Doing constant.toString() on the constants will return "1" and "2" and Color.RED would not be resolved. Reproducible: Didn't try Steps to Reproduce: 1. Create an enum that overrides toString() and return anything that is not the name of the method (constant name). 2. Try to resolve the enum constant. 3. No enum constant will be found even though there is a match.