Find exception thrown by 3rd party library

1k Views Asked by At

I hope I can explain this correctly. I am using the Javolution library to do reading and writing of an XML config file. I'm using XMLStreamReader/Writer. During reading, I'm looking to read a tag and store its attributes in a LinkedHashMap. However, I'm having an exception being thrown, that to me looks to make no sense due to when it's thrown and what's currently going on in the code.

Using the Eclipse debugger, the exception is being thrown when an attribute's key and value is being added to my map.

public class Element {
   private HashMap<String, String> attributes = new LinkedHashMap<String, String>();
   ...

   public void setAttribute(String key, String value) {
      ...
      attributes.put(key, value);
   }
}

Straight after the key and value are added, this catches an exception from Javolution:

javolution.xml.stream.XMLStreamException: Local name cannot be null

Neither key or value are null. When they are being added to the map, I cannot step into the code further to see where the exception is being thrown, there is no stack trace, no file/line number shown anywhere to explain where or even how the exception is thrown.

From a quick google search of older implementation of Javolution, I can see that this particular exception is only thrown using a few methods of the XMLStreamWriterImpl type. I've set breakpoints at each use I have of these methods, but the debugger doesn't catch them being used until much later in the code (and my localName variable is initialised at declaration).

Would anyone have any advice for how I could determine why this exception is being thrown?

Stack Trace:

Java HotSpot(TM) 64-Bit Server VM[localhost:3999]   
    Thread [main] (Suspended)   
        XMLImplMain$Element.setAttribute(String, String) line: 827  
        XMLImplMain.translate(Element) line: 133    
        XMLImplMain.translate(Element) line: 140    
        XMLImplMain.translate(Element) line: 140    
        XMLImplMain.loadXML(String) line: 118   
        Bootstrap.main(String[]) line: 32   
    Thread [EventWriter] (Running)  
1

There are 1 best solutions below

2
On BEST ANSWER

It's possible that this Javolution library is not correctly compiled, without the argument -g when compiling via javac perhaps and this will make the output jar lack of debug information. You can find the corresponding source code of the jar you currently working on, and recompile it with sufficient arguments to make it debugable by yourself.

Or, there is a workaround which is way more complicated but no customizing compilation is needed, writing a BTrace script and catch the initialization of all the XMLStreamException and then print out the stacktrace, like this:

package com.sun.btrace.samples;
import com.sun.btrace.annotations.*;
import static com.sun.btrace.BTraceUtils.*;

@BTrace 
public class OnThrow {  
    @OnMethod(clazz = "javolution.xml.stream.XMLStreamException", method = "<init>", location = @Location(Kind.RETURN))
    public static void endMethod(@Self Exception self) {
        jstack();
    }
}

and there is similar example here. You can dig a little deeper here.