dev@fi.java.net

Re: Wierd exception in JAXB deserialization

From: Oleksiy Stashok <Oleksiy.Stashok_at_Sun.COM>
Date: Fri, 29 Feb 2008 10:54:24 +0100

Hello,

can you pls. attach byte[] dump, result of serialize method call?

Thanks.

WBR,
Alexey.

On Feb 29, 2008, at 0:03 , Avinash Lakshman wrote:

> Could someone please give me some pointers as to where I should
> start looking when I attempt tracking this one?
>
> We are reading some bytes from a TCP socket and submitting these
> bytes to be deserialized on a separate thread in a dedicated thread
> pool. Every once in a while I see this wierd exception.
> java.io.IOException: Illegal state for UTF-8 encoded string
> at
> com
> .sun
> .xml.fastinfoset.Decoder.decodeUtf8StringIllegalState(Decoder.java:
> 1780)
> at
> com
> .sun
> .xml
> .fastinfoset.Decoder.decodeTwoToFourByteUtf8Character(Decoder.java:
> 1532)
> at
> com
> .sun
> .xml.fastinfoset.Decoder.decodeUtf8StringIntoCharBuffer(Decoder.java:
> 1471)
> at
> com
> .sun
> .xml.fastinfoset.Decoder.decodeUtf8StringAsCharBuffer(Decoder.java:
> 1392)
> at
> com
> .sun
> .xml
> .fastinfoset
> .stax
> .StAXDocumentParser
> .processUtf8CharacterString(StAXDocumentParser.java:488)
> at
> com
> .sun
> .xml
> .fastinfoset.stax.StAXDocumentParser.next(StAXDocumentParser.java:323)
> at
> com
> .sun
> .xml
> .bind
> .v2
> .runtime
> .unmarshaller.FastInfosetConnector.bridge(FastInfosetConnector.java:
> 130)
> at
> com
> .sun
> .xml
> .bind
> .v2
> .runtime
> .unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:358)
> at
> com
> .sun
> .xml
> .bind
> .v2
> .runtime
> .unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:330)
> at
> com
> .firm
> .infrastructure
> .net.io.BinarySerializer.deserialize(BinarySerializer.java:177)
> at
> com
> .firm
> .infrastructure
> .net.MessageDeserializationTask.run(MessageDeserializationTask.java:
> 36)
> at java.util.concurrent.Executors
> $RunnableAdapter.call(Executors.java:471)
> at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
> at java.util.concurrent.FutureTask.run(FutureTask.java:166)
> at
> java
> .util
> .concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
> at java.util.concurrent.ThreadPoolExecutor
> $Worker.run(ThreadPoolExecutor.java:603)
> at java.lang.Thread.run(Thread.java:675)
>
> Here is how I implement the serialization/deserialization:
>
> public byte[] serialize(Object message) throws IOException
> {
> byte[] bytes = new byte[0];
> long startTime = System.currentTimeMillis();
>
> if ( message != null )
> {
> try
> {
> JAXBContext context =
> SerializationManager.getContext();
> Marshaller m = context.createMarshaller();
> FastByteArrayOutputStream bos = new
> FastByteArrayOutputStream();
> StAXDocumentSerializer sw = new
> StAXDocumentSerializer();
> sw.setOutputStream(bos);
> m.marshal(message, (XMLStreamWriter)sw);
> bytes = bos.toByteArray();
> }
> catch ( JAXBException ex )
> {
> SerializationManager.handleJAXBException(ex, message);
> }
> }
> logger_.info("JAXB serialize: " +
> (System.currentTimeMillis() - startTime) + " ms.");
> return bytes;
> }
>
> public Object deserialize(byte[] bytes) throws IOException
> {
> Object message = null;
> long startTime = System.currentTimeMillis();
> try
> {
> JAXBContext context = SerializationManager.getContext();
> Unmarshaller um = context.createUnmarshaller();
> FastByteArrayInputStream bis = new
> FastByteArrayInputStream(bytes);
> XMLStreamReader xr = new StAXDocumentParser(bis);
> message = um.unmarshal(xr);
> }
> catch ( JAXBException ex )
> {
> SerializationManager.handleJAXBException(ex);
> }
> logger_.info("JAXB deserialize: " +
> (System.currentTimeMillis() - startTime) + " ms.");
> return message;
> }
>
> What would cause this? Please advice.
>
> Thanks
> A
>
> Connect and share in new ways with Windows Live. Get it now!