Author: nagy Date: Thu Sep 24 02:22:02 2009 New Revision: 818346 URL: http://svn.apache.org/viewvc?rev=818346&view=rev Log: Fix potential NPE during serialization if an encoding has not been set for the OMOutputFormat.
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMSourcedElementTest.java Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java?rev=818346&r1=818345&r2=818346&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java Thu Sep 24 02:22:02 2009 @@ -214,7 +214,7 @@ * @return Returns encoding string. */ public String getCharSetEncoding() { - return this.charSetEncoding; + return (this.charSetEncoding != null)?this.charSetEncoding:DEFAULT_CHAR_SET_ENCODING; } public void setCharSetEncoding(String charSetEncoding) { Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMSourcedElementTest.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMSourcedElementTest.java?rev=818346&r1=818345&r2=818346&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMSourcedElementTest.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMSourcedElementTest.java Thu Sep 24 02:22:02 2009 @@ -139,7 +139,15 @@ String payload = new String(bytes, "utf-16"); assertTrue("The obtained bytes did not match the payload", payload1.equals(payload)); - + + // Test getting the raw bytes with the default encoding + OMOutputFormat outputFormat = new OMOutputFormat(); + baos = new ByteArrayOutputStream(); + ds.serialize(baos, outputFormat); + output = baos.toString(OMOutputFormat.DEFAULT_CHAR_SET_ENCODING); + System.out.println(output); + assertTrue("The obtained bytes did not match the payload", + payload1.equals(output)); } /**