1

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)  
MeanwhileInHell
  • 6,780
  • 17
  • 57
  • 106
  • Is the validation enabled in this XLStream reader ? Does your XML comply with your XSD ? – NiranjanBhat Jan 15 '13 at 10:56
  • 1
    You can create [breakpoint for exceptions in Eclipse](http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fviews%2Fbreakpoints%2Fref-addexception_viewaction.htm) – András Kerekes Jan 15 '13 at 10:57
  • @archer Just added ST AndrásKerekes I tried that, but it doesn't seem to actually break when the exception is found. The only reason I know an exception is thrown is that when I click on the "this" variable in the Variables tab, it is given as the value. If you didn't click it, then you wouldn't notice the exception as the code follows on as normal. NiranjanBhat No, I haven't tried that, I'll give it a go now. Thanks to all for your comments. – MeanwhileInHell Jan 15 '13 at 11:52
  • Found the cause of the problem using suggestion from @AndrásKerekes. Also looking into BTrace a lot more for future, looks very useful. Thanks again to all. – MeanwhileInHell Jan 17 '13 at 11:30

1 Answers1

3

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.

Gavin Xiong
  • 957
  • 6
  • 9
  • This looks great and very useful. I've downloaded the plugin for VisualVM and used your script above. However, for some reason it won't catch the exception which is very strange (its not the script, if I change it a NullPointerException, it catches that, but then so does Eclipse). The way the XMLStreamException is thrown is very strange, it just seems to be silently thrown somehow. I wonder if the problem with BTrace catching it is that I haven't downloaded the source code, so it can't instrument it? Will try that. Either way, this is a great tool that I will definitely keep using. – MeanwhileInHell Jan 21 '13 at 12:18
  • @NomNomNom If so, maybe you can catch some other event that is prior to the code line when the XMLStreamException is born to figure out the runtime value of some important variables, the 'Local' for example. Perhaps they will help you solve the puzzle. You may have to do this according to the source code and decompilation is necessary if the source code is unavailable. – Gavin Xiong Jan 21 '13 at 12:51