Skip to content

Commit 5a4971f

Browse files
AXIS2-6074 Return null for empty enum values instead of throwing
When an empty XML element is sent for an enum field (e.g., <eventType/>), the generated fromValue() method looked up the empty string in the enum table, got null, and threw IllegalArgumentException. This caused a cryptic SOAP fault ("unknown") with null HTTP status. Fix: in both bean and helpermode templates, allow null/empty values to return null from fromValue() instead of throwing. The bean template previously had this guard only for string property types — now it applies to all types. The helpermode template had no guard at all. This restores the Axis2 1.6 behavior where empty enum elements were handled gracefully.
1 parent bfd03e4 commit 5a4971f

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate-bean.xsl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,8 @@
18111811
</xsl:choose>
18121812

18131813
// handle unexpected enumeration values properly
1814-
if (enumeration == null <xsl:if test="$propertyType='string'">&amp;&amp; !((value == null) || (value.equals("")))</xsl:if>) {
1814+
// AXIS2-6074: allow null/empty values for all types, not just string
1815+
if (enumeration == null &amp;&amp; value != null &amp;&amp; !value.toString().trim().isEmpty()) {
18151816
<xsl:choose>
18161817
<xsl:when test="$ignoreunexpected">
18171818
log.warn("Unexpected value " + value + " for enumeration <xsl:value-of select="$name"/>");

modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate-helpermode.xsl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@
253253
</xsl:otherwise>
254254
</xsl:choose>
255255

256-
if (enumeration==null) throw new java.lang.IllegalArgumentException();
256+
// AXIS2-6074: return null for empty/null values instead of throwing
257+
if (enumeration==null &amp;&amp; value != null &amp;&amp; !value.toString().trim().isEmpty()) throw new java.lang.IllegalArgumentException();
257258
return enumeration;
258259
}
259260
public static <xsl:value-of select="$name"/> fromString(java.lang.String value)

0 commit comments

Comments
 (0)