java.lang.ArrayIndexOutOfBoundsException: -4

Spring JIRA | Paul Nyheim | 6 years ago
  1. 0

    When Upgrading to Spring Framework version 3, we got an issue with our Spring WS Endpoints. Sometimes it would fail with the following exception: {noformat} 12:19:14.742 [12122157@qtp-3705235-0] DEBUG o.s.w.s.server.SoapMessageDispatcher - Endpoint invocation resulted in exception - responding with Fault java.lang.ArrayIndexOutOfBoundsException: -4 at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startPrefixMapping(UnmarshallingContext.java:806) ~[jaxb-impl-2.2.1.jar:2.2.1] at com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startPrefixMapping(InterningXmlVisitor.java:81) ~[jaxb-impl-2.2.1.jar:2.2.1] at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startPrefixMapping(SAXConnector.java:116) ~[jaxb-impl-2.2.1.jar:2.2.1] at org.springframework.xml.stream.StaxStreamXmlReader.startPrefixMapping(StaxStreamXmlReader.java:170) ~[spring-xml-1.5.9.jar:1.5.9] at org.springframework.xml.stream.StaxStreamXmlReader.handleStartElement(StaxStreamXmlReader.java:145) ~[spring-xml-1.5.9.jar:1.5.9] at org.springframework.xml.stream.StaxStreamXmlReader.parseInternal(StaxStreamXmlReader.java:80) ~[spring-xml-1.5.9.jar:1.5.9] at org.springframework.xml.stream.AbstractStaxXmlReader.parse(AbstractStaxXmlReader.java:128) ~[spring-xml-1.5.9.jar:1.5.9] at org.springframework.xml.stream.AbstractStaxXmlReader.parse(AbstractStaxXmlReader.java:111) ~[spring-xml-1.5.9.jar:1.5.9] at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:211) ~[jaxb-impl-2.2.1.jar:2.2.1] at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:184) ~[jaxb-impl-2.2.1.jar:2.2.1] at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:119) ~[jaxb-api-2.2.1.jar:na] at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:102) ~[jaxb-api-2.2.1.jar:na] at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:581) ~[spring-oxm-3.0.5.RELEASE.jar:3.0.5.RELEASE] at org.springframework.ws.support.MarshallingUtils.unmarshal(MarshallingUtils.java:62) ~[spring-ws-core-1.5.9.jar:1.5.9] at org.springframework.ws.server.endpoint.adapter.MarshallingMethodEndpointAdapter.unmarshalRequest(MarshallingMethodEndpointAdapter.java:143) ~[spring-ws-core-1.5.9.jar:1.5.9] at org.springframework.ws.server.endpoint.adapter.MarshallingMethodEndpointAdapter.invokeInternal(MarshallingMethodEndpointAdapter.java:134) ~[spring-ws-core-1.5.9.jar:1.5.9] at org.springframework.ws.server.endpoint.adapter.AbstractMethodEndpointAdapter.invoke(AbstractMethodEndpointAdapter.java:58) ~[spring-ws-core-1.5.9.jar:1.5.9] at org.springframework.ws.server.MessageDispatcher.dispatch(MessageDispatcher.java:228) [spring-ws-core-1.5.9.jar:1.5.9] ... {noformat} I noticed that my classpath would contain two versions of spring-oxm, one from spring-ws, and one from springframework. If I rearranged my dependencies, and made sure that only the old one from spring-ws was present on my classpath, all requests would work again. So there seems to be a problem introduced into spring-oxm when it was moved into springframework. I have created a complete maven project that will recreate this issue. The pom.xml included contains two profiles * spring-oxm-from-springframework ** is active by default ** defines dependency to spring-oxm-3.0.5.RELEASE (and excludes spring-oxm from spring-ws) * spring-oxm-from-springws ** can be triggered with property {{-Dx}} ** defines dependency to spring-oxm-1.5.9 Invoking {{mvn clean test}} (_spring-oxm-from-springframework_ profile) on the project will fail one of the tests, while invoking it with the other profile {{mvn clean test -Dx}} (_spring-oxm-from-springws_) passes both tests The difference between the two tests is different input payload xmls. (see {{src/test/resources/}} for input xmls) The content is identical, however on the different xml files, the namespace declarations are defined in the root element in one file, and on every element on the other file. Content from xml files included below: {code:xml|title=fails.xml} <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> <Body xmlns="http://schemas.xmlsoap.org/soap/envelope/"> <SaveForecastsRequest xmlns="urn://schemas/message/TradeService/1"> <ForecastList xmlns="urn://schemas/message/TradeService/1"> <Forecasts xmlns="urn://schemas/message/TradeService/1"> <Version xmlns="urn://schemas/data/DomainObjectType/1">1</Version> <CreatedBy xmlns="urn://schemas/data/DomainObjectType/1">user</CreatedBy> <CreatedWhen xmlns="urn://schemas/data/DomainObjectType/1">0001-01-01T00:00:00</CreatedWhen> <Active xmlns="urn://schemas/data/DomainObjectType/1">false</Active> <Forecast xmlns="urn://schemas/data/Trade/1"> <Value xmlns="urn://schemas/data/ValueWithUnit/1">10</Value> <UnitId xmlns="urn://schemas/data/ValueWithUnit/1">KWH</UnitId> </Forecast> </Forecasts> </ForecastList> </SaveForecastsRequest> </Body> </Envelope> {code} {code:xml|title=works.xml} <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Body> <message:SaveForecastsRequest xmlns:message="urn://schemas/message/TradeService/1" xmlns:trade="urn://schemas/data/Trade/1" xmlns:value="urn://schemas/data/ValueWithUnit/1" xmlns:domainObject="urn://schemas/data/DomainObjectType/1"> <message:ForecastList> <message:Forecasts> <domainObject:Version>1</domainObject:Version> <domainObject:CreatedBy>user</domainObject:CreatedBy> <domainObject:CreatedWhen>0001-01-01T00:00:00</domainObject:CreatedWhen> <domainObject:Active>false</domainObject:Active> <trade:Forecast> <value:Value>10</value:Value> <value:UnitId>KWH</value:UnitId> </trade:Forecast> </message:Forecasts> </message:ForecastList> </message:SaveForecastsRequest> </s:Body> </s:Envelope> {code} Both xml files are well-formed and valid according to the xsd's ({{src/main/resources/data, src/main/resource/message}}) (Interesting sidenote, if I enable payload validation with the {{org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor}}, both profiles will fail the one test using {{fails.xml}}. Just change the {{validateRequest}} property of that bean declaration in {{src/main/resources/ws.xml}} to {{true}}. Now the test will fail with another stacktrace - similar in nature, but originating from inside xerces...)

    Spring JIRA | 6 years ago | Paul Nyheim
    java.lang.ArrayIndexOutOfBoundsException: -4
  2. 0

    When Upgrading to Spring Framework version 3, we got an issue with our Spring WS Endpoints. Sometimes it would fail with the following exception: {noformat} 12:19:14.742 [12122157@qtp-3705235-0] DEBUG o.s.w.s.server.SoapMessageDispatcher - Endpoint invocation resulted in exception - responding with Fault java.lang.ArrayIndexOutOfBoundsException: -4 at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startPrefixMapping(UnmarshallingContext.java:806) ~[jaxb-impl-2.2.1.jar:2.2.1] at com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startPrefixMapping(InterningXmlVisitor.java:81) ~[jaxb-impl-2.2.1.jar:2.2.1] at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startPrefixMapping(SAXConnector.java:116) ~[jaxb-impl-2.2.1.jar:2.2.1] at org.springframework.xml.stream.StaxStreamXmlReader.startPrefixMapping(StaxStreamXmlReader.java:170) ~[spring-xml-1.5.9.jar:1.5.9] at org.springframework.xml.stream.StaxStreamXmlReader.handleStartElement(StaxStreamXmlReader.java:145) ~[spring-xml-1.5.9.jar:1.5.9] at org.springframework.xml.stream.StaxStreamXmlReader.parseInternal(StaxStreamXmlReader.java:80) ~[spring-xml-1.5.9.jar:1.5.9] at org.springframework.xml.stream.AbstractStaxXmlReader.parse(AbstractStaxXmlReader.java:128) ~[spring-xml-1.5.9.jar:1.5.9] at org.springframework.xml.stream.AbstractStaxXmlReader.parse(AbstractStaxXmlReader.java:111) ~[spring-xml-1.5.9.jar:1.5.9] at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:211) ~[jaxb-impl-2.2.1.jar:2.2.1] at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:184) ~[jaxb-impl-2.2.1.jar:2.2.1] at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:119) ~[jaxb-api-2.2.1.jar:na] at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:102) ~[jaxb-api-2.2.1.jar:na] at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:581) ~[spring-oxm-3.0.5.RELEASE.jar:3.0.5.RELEASE] at org.springframework.ws.support.MarshallingUtils.unmarshal(MarshallingUtils.java:62) ~[spring-ws-core-1.5.9.jar:1.5.9] at org.springframework.ws.server.endpoint.adapter.MarshallingMethodEndpointAdapter.unmarshalRequest(MarshallingMethodEndpointAdapter.java:143) ~[spring-ws-core-1.5.9.jar:1.5.9] at org.springframework.ws.server.endpoint.adapter.MarshallingMethodEndpointAdapter.invokeInternal(MarshallingMethodEndpointAdapter.java:134) ~[spring-ws-core-1.5.9.jar:1.5.9] at org.springframework.ws.server.endpoint.adapter.AbstractMethodEndpointAdapter.invoke(AbstractMethodEndpointAdapter.java:58) ~[spring-ws-core-1.5.9.jar:1.5.9] at org.springframework.ws.server.MessageDispatcher.dispatch(MessageDispatcher.java:228) [spring-ws-core-1.5.9.jar:1.5.9] ... {noformat} I noticed that my classpath would contain two versions of spring-oxm, one from spring-ws, and one from springframework. If I rearranged my dependencies, and made sure that only the old one from spring-ws was present on my classpath, all requests would work again. So there seems to be a problem introduced into spring-oxm when it was moved into springframework. I have created a complete maven project that will recreate this issue. The pom.xml included contains two profiles * spring-oxm-from-springframework ** is active by default ** defines dependency to spring-oxm-3.0.5.RELEASE (and excludes spring-oxm from spring-ws) * spring-oxm-from-springws ** can be triggered with property {{-Dx}} ** defines dependency to spring-oxm-1.5.9 Invoking {{mvn clean test}} (_spring-oxm-from-springframework_ profile) on the project will fail one of the tests, while invoking it with the other profile {{mvn clean test -Dx}} (_spring-oxm-from-springws_) passes both tests The difference between the two tests is different input payload xmls. (see {{src/test/resources/}} for input xmls) The content is identical, however on the different xml files, the namespace declarations are defined in the root element in one file, and on every element on the other file. Content from xml files included below: {code:xml|title=fails.xml} <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> <Body xmlns="http://schemas.xmlsoap.org/soap/envelope/"> <SaveForecastsRequest xmlns="urn://schemas/message/TradeService/1"> <ForecastList xmlns="urn://schemas/message/TradeService/1"> <Forecasts xmlns="urn://schemas/message/TradeService/1"> <Version xmlns="urn://schemas/data/DomainObjectType/1">1</Version> <CreatedBy xmlns="urn://schemas/data/DomainObjectType/1">user</CreatedBy> <CreatedWhen xmlns="urn://schemas/data/DomainObjectType/1">0001-01-01T00:00:00</CreatedWhen> <Active xmlns="urn://schemas/data/DomainObjectType/1">false</Active> <Forecast xmlns="urn://schemas/data/Trade/1"> <Value xmlns="urn://schemas/data/ValueWithUnit/1">10</Value> <UnitId xmlns="urn://schemas/data/ValueWithUnit/1">KWH</UnitId> </Forecast> </Forecasts> </ForecastList> </SaveForecastsRequest> </Body> </Envelope> {code} {code:xml|title=works.xml} <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Body> <message:SaveForecastsRequest xmlns:message="urn://schemas/message/TradeService/1" xmlns:trade="urn://schemas/data/Trade/1" xmlns:value="urn://schemas/data/ValueWithUnit/1" xmlns:domainObject="urn://schemas/data/DomainObjectType/1"> <message:ForecastList> <message:Forecasts> <domainObject:Version>1</domainObject:Version> <domainObject:CreatedBy>user</domainObject:CreatedBy> <domainObject:CreatedWhen>0001-01-01T00:00:00</domainObject:CreatedWhen> <domainObject:Active>false</domainObject:Active> <trade:Forecast> <value:Value>10</value:Value> <value:UnitId>KWH</value:UnitId> </trade:Forecast> </message:Forecasts> </message:ForecastList> </message:SaveForecastsRequest> </s:Body> </s:Envelope> {code} Both xml files are well-formed and valid according to the xsd's ({{src/main/resources/data, src/main/resource/message}}) (Interesting sidenote, if I enable payload validation with the {{org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor}}, both profiles will fail the one test using {{fails.xml}}. Just change the {{validateRequest}} property of that bean declaration in {{src/main/resources/ws.xml}} to {{true}}. Now the test will fail with another stacktrace - similar in nature, but originating from inside xerces...)

    Spring JIRA | 6 years ago | Paul Nyheim
    java.lang.ArrayIndexOutOfBoundsException: -4
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    Halloween Easter Egg Bug

    GitHub | 1 month ago | TLomon
    java.lang.ArrayIndexOutOfBoundsException: 4
  5. 0

    Bitap pattern matching fails for sequences with N's

    GitHub | 11 months ago | mikessh
    java.lang.ArrayIndexOutOfBoundsException: 4

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.ArrayIndexOutOfBoundsException

      -4

      at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startPrefixMapping()
    2. Old JAXB Runtime
      SAXConnector.startPrefixMapping
      1. com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startPrefixMapping(UnmarshallingContext.java:806)[jaxb-impl-2.2.1.jar:2.2.1]
      2. com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startPrefixMapping(InterningXmlVisitor.java:81)[jaxb-impl-2.2.1.jar:2.2.1]
      3. com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startPrefixMapping(SAXConnector.java:116)[jaxb-impl-2.2.1.jar:2.2.1]
      3 frames
    3. org.springframework.xml
      AbstractStaxXmlReader.parse
      1. org.springframework.xml.stream.StaxStreamXmlReader.startPrefixMapping(StaxStreamXmlReader.java:170)[spring-xml-1.5.9.jar:1.5.9]
      2. org.springframework.xml.stream.StaxStreamXmlReader.handleStartElement(StaxStreamXmlReader.java:145)[spring-xml-1.5.9.jar:1.5.9]
      3. org.springframework.xml.stream.StaxStreamXmlReader.parseInternal(StaxStreamXmlReader.java:80)[spring-xml-1.5.9.jar:1.5.9]
      4. org.springframework.xml.stream.AbstractStaxXmlReader.parse(AbstractStaxXmlReader.java:128)[spring-xml-1.5.9.jar:1.5.9]
      5. org.springframework.xml.stream.AbstractStaxXmlReader.parse(AbstractStaxXmlReader.java:111)[spring-xml-1.5.9.jar:1.5.9]
      5 frames
    4. Old JAXB Runtime
      UnmarshallerImpl.unmarshal
      1. com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:211)[jaxb-impl-2.2.1.jar:2.2.1]
      2. com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:184)[jaxb-impl-2.2.1.jar:2.2.1]
      2 frames
    5. Java RT
      AbstractUnmarshallerImpl.unmarshal
      1. javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:119)[jaxb-api-2.2.1.jar:na]
      2. javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:102)[jaxb-api-2.2.1.jar:na]
      2 frames
    6. Spring Object/XML Marshalling
      Jaxb2Marshaller.unmarshal
      1. org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:581)[spring-oxm-3.0.5.RELEASE.jar:3.0.5.RELEASE]
      1 frame
    7. Spring WS Core
      MessageDispatcher.dispatch
      1. org.springframework.ws.support.MarshallingUtils.unmarshal(MarshallingUtils.java:62)[spring-ws-core-1.5.9.jar:1.5.9]
      2. org.springframework.ws.server.endpoint.adapter.MarshallingMethodEndpointAdapter.unmarshalRequest(MarshallingMethodEndpointAdapter.java:143)[spring-ws-core-1.5.9.jar:1.5.9]
      3. org.springframework.ws.server.endpoint.adapter.MarshallingMethodEndpointAdapter.invokeInternal(MarshallingMethodEndpointAdapter.java:134)[spring-ws-core-1.5.9.jar:1.5.9]
      4. org.springframework.ws.server.endpoint.adapter.AbstractMethodEndpointAdapter.invoke(AbstractMethodEndpointAdapter.java:58)[spring-ws-core-1.5.9.jar:1.5.9]
      5. org.springframework.ws.server.MessageDispatcher.dispatch(MessageDispatcher.java:228)[spring-ws-core-1.5.9.jar:1.5.9]
      5 frames