question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Async parse of simple document fails with WFCException: Unexpected character 'd' (code 100) in epilog

See original GitHub issue

This is a test case with the simplest document I could find. The code reproducing the problem is a copy-paste of an official example with a small fix.

  @Test
  public void asynchronousParseSmallestDocument() throws Exception {
    final String xml = 
//        "<?xml version=\"1.0\" encoding=\"US-ASCII\"?>" +
        "<d/>" ;

    final AsyncXMLInputFactory asyncXmlInputFactory = new InputFactoryImpl() ;
    final AsyncXMLStreamReader< AsyncByteArrayFeeder > xmlStreamReader =
        asyncXmlInputFactory.createAsyncFor( xml.getBytes( Charsets.US_ASCII ) ) ;
    final AsyncByteArrayFeeder inputFeeder = xmlStreamReader.getInputFeeder() ;

    byte[] xmlBytes = xml.getBytes() ;
    int bufferFeedLength = 1 ; 
    int currentByteOffset = 0 ;
    int type ;
    do{
      while( ( type = xmlStreamReader.next() ) == AsyncXMLStreamReader.EVENT_INCOMPLETE ) {
        byte[] buffer = new byte[]{ xmlBytes[ currentByteOffset ] } ;
        currentByteOffset ++ ;
        inputFeeder.feedInput( buffer, 0, bufferFeedLength ) ;
        if( currentByteOffset >= xmlBytes.length ) {
          inputFeeder.endOfInput() ;
        }
      }
      switch( type ) {
        case XMLEvent.START_DOCUMENT :
          LOGGER.debug( "start document" ) ;
          break ;
        case XMLEvent.START_ELEMENT :
          LOGGER.debug( "start element: " + xmlStreamReader.getName() ) ;
          break ;
        case XMLEvent.CHARACTERS :
          LOGGER.debug( "characters: " + xmlStreamReader.getText() ) ;
          break ;
        case XMLEvent.END_ELEMENT :
          LOGGER.debug( "end element: " + xmlStreamReader.getName() ) ;
          break ;
        case XMLEvent.END_DOCUMENT :
          LOGGER.debug( "end document" ) ;
          break ;
        default :
          break ;
      }
    } while( type != XMLEvent.END_DOCUMENT ) ;

    xmlStreamReader.close() ;
  }

This is what I get:

15:23:41.388 DEBUG [main] c.o.s.m.c.x.SingleContactXmlParserTest - start document
15:23:41.394 DEBUG [main] c.o.s.m.c.x.SingleContactXmlParserTest - start element: d
15:23:41.394 DEBUG [main] c.o.s.m.c.x.SingleContactXmlParserTest - end element: d

com.fasterxml.aalto.WFCException: Unexpected character 'd' (code 100) in epilog (unbalanced start/end tags?)
 at [row,col {unknown-source}]: [1,7]

	at com.fasterxml.aalto.in.XmlScanner.reportInputProblem(XmlScanner.java:1333)
	at com.fasterxml.aalto.in.XmlScanner.throwUnexpectedChar(XmlScanner.java:1498)
	at com.fasterxml.aalto.in.XmlScanner.reportPrologUnexpChar(XmlScanner.java:1358)
	at com.fasterxml.aalto.async.AsyncByteArrayScanner.nextFromProlog(AsyncByteArrayScanner.java:1068)
	at com.fasterxml.aalto.stax.StreamReaderImpl.next(StreamReaderImpl.java:802)
	at com.otcdlink.server.model.contact.xml.SingleContactXmlParserTest.asynchronousParseSmallestDocument(SingleContactXmlParserTest.java:102)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

I’m using aalto-xml 1.0.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
cowtowncodercommented, Apr 10, 2018

@aamalik Thank you for sharing! And yes, I understand no one asks questions to annoy. Nor should it, it’s just that across many repos it sometimes feels questions are asked without reading the full thread. And it is difficult to also know how difficult they are to follow. So frustration I had was more general; apologies for directing it to you and others here.

But the important thing is that there is more information now, and error handling in 1.1.0 is better to also help recognizing the issue. Thank you everyone in helping us get there.

1reaction
asfandyar-malikcommented, Apr 10, 2018

Standalone Runnable Java Code incase somebody wants async xml file reading.


import com.fasterxml.aalto.AsyncByteArrayFeeder;
import com.fasterxml.aalto.AsyncXMLInputFactory;
import com.fasterxml.aalto.AsyncXMLStreamReader;
import com.fasterxml.aalto.stax.InputFactoryImpl;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.XMLEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;

public class AkkaGpxTest {

    public ArrayList<LatLon> extractLatLonFromFile() throws XMLStreamException, IOException {

        final AsyncXMLInputFactory f = new InputFactoryImpl();
        AsyncXMLStreamReader<AsyncByteArrayFeeder> sc = null;

        ClassLoader classLoader = getClass().getClassLoader();
        File file = new File(classLoader.getResource("AnyXMLFile.xml").getFile());

        //init array with file length
        byte[] xmlBytes = new byte[(int) file.length()];

        FileInputStream fis = new FileInputStream(file);
        fis.read(xmlBytes); //read file into bytes[]
        fis.close();

        sc = f.createAsyncForByteArray();

        ArrayList<LatLon> latlonList = new ArrayList<LatLon>();

        int bufferFeedLength = 1 ;
        int currentByteOffset = 0 ;
        int type ;
        do{
            while( (type = sc.next()) == AsyncXMLStreamReader.EVENT_INCOMPLETE ) {
                byte[] buffer = new byte[]{ xmlBytes[ currentByteOffset ] } ;
                currentByteOffset ++ ;
                sc.getInputFeeder().feedInput( buffer, 0, bufferFeedLength ) ;
                if( currentByteOffset >= xmlBytes.length ) {
                    sc.getInputFeeder().endOfInput() ;
                }
            }
            switch( type ) {

                case XMLEvent.START_DOCUMENT :
                    System.out.println( "start document" ) ;
                    break ;

                case XMLEvent.START_ELEMENT :
                    System.out.println( "start element: " + sc.getName());
                    break ;

                case XMLEvent.CHARACTERS :
                    System.out.println( "characters: " + sc.getText()) ;
                    break ;

                case XMLEvent.END_ELEMENT :
                    System.out.println( "end element: " + sc.getName()) ;
                    break ;

                case XMLEvent.END_DOCUMENT :
                    System.out.println( "end document" ) ;
                    break ;

                default :
                    break ;
            }
        } while( type != XMLEvent.END_DOCUMENT ) ;
        sc.close();

    }

    public static void main(String[] args) throws IOException, XMLStreamException {

        AkkaGpxTest jt = new AkkaGpxTest();
        jt.extractLatLonFromFile();
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unexpected character ('d' (code 100)): was expecting comma ...
org.codehaus.jackson.JsonParseException: Unexpected character ('d' (code 100)): was expecting comma to separate OBJECT entries\n · Ask Question.
Read more >
[Solved] Encountered unexpected character '<'. - CodeProject
Sometimes this error occurs if you are returning XML strings. I too had a similar problem returning XML as string.
Read more >
Unexpected character encountered while parsing value - MSDN
Hello, I am evaluating DocumentDB as backend for our new project and following MS Documentation, wrote a simple code.
Read more >
Text Search Engine reason codes - IBM
Text Search Engine can produce error codes and reasons for the error. 0: Operation performed successfully - no error occurred.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found