1 Reply Latest reply on Jun 1, 2006 5:01 AM by Martin Steinle

    java.lang.ArrayIndexOutOfBoundsException / NullPointerExcept

    Martin Steinle Newbie

      Hi there,

      I was trying to throw an Exception with an array property from a SLSB with a web services endpoint.
      At first, here my exception code:

      public class ValidationException extends Exception {
       private ValidationProblem[] validationProblems;
      
       public ValidationException() {
       }
      
       public ValidationException(ValidationProblem[] validationProblems) {
       this.validationProblems = validationProblems;
       }
      
       public ValidationProblem[] getValidationProblems() {
       return validationProblems;
       }
      
       public void setValidationProblems(ValidationProblem[] problems) {
       this.validationProblems = validationProblems;
       }

      And the ValidationProblem class:
      public class ValidationProblem implements Serializable {
      
       protected String path;
       protected String type;
       protected String message;
      
       public ValidationProblem() {
       }
      
       public ValidationProblem(String path, String type, String message) {
       this.path = path;
       this.type = type;
       this.message = message;
       }
      
      [... public getters and setters for the three properties]

      My code is running on JBoss 4.0.3sp1 with the ws4ee web services stack.
      When I throw a ValidationException, say with 3 ValidationProblems, there is a NullPointerException when it is serialized.
      If I initialize the validationProblems[] in the ValidationException class with a ValidationProblem[] of length 0 (or 1 or 2) in the no-args constructor, there is an ArrayIndexOutOfBoundsException during serialization. If I initialize it in the no-args constructor with an array of length 3 or greater, there is no problem. So it seems to me as if the serializer does not create an array but simply put values in it, hoping it is big enough.

      Here is the stacktrace:
      java.lang.ArrayIndexOutOfBoundsException
       at java.lang.reflect.Array.set(Native Method)
       at org.jboss.axis.utils.BeanPropertyDescriptor.set(BeanPropertyDescriptor.java:255)
       at org.jboss.axis.encoding.ser.BeanPropertyTarget.set(BeanPropertyTarget.java:183)
       at org.jboss.axis.encoding.DeserializerImpl.valueComplete(DeserializerImpl.java:305)
       at org.jboss.axis.encoding.DeserializerImpl.endElement(DeserializerImpl.java:590)
       at org.jboss.axis.encoding.DeserializationContextImpl.endElement(DeserializationContextImpl.java:1249)
       at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
       at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
       at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
       at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
       at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
       at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
       at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
       at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
       at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
       at javax.xml.parsers.SAXParser.parse(Unknown Source)
       at org.jboss.axis.encoding.DeserializationContextImpl.parse(DeserializationContextImpl.java:257)
       at org.jboss.axis.MessagePart.getAsSOAPEnvelope(MessagePart.java:684)
       at org.jboss.axis.Message.getSOAPEnvelope(Message.java:428)
       at org.jboss.axis.Message.getContentType(Message.java:494)
       at org.jboss.axis.transport.http.AxisServlet.doPost(AxisServlet.java:977)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
       at org.jboss.axis.transport.http.AxisServletBase.service(AxisServletBase.java:370)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
       at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
       at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
       at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
       at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
       at java.lang.Thread.run(Thread.java:595)


      The stacktrace of the NullPointerException looks similar.
      Is there a mistake I made, or is this a bug? If so, is there a workaround?

      Thanks in advance for any help.
      Martin