NPE in parser->getDOMImplementation() with CNI

Sam Ruby <[email protected]>
Newsgroups gmane.comp.gcc.java.devel
Message-ID <[email protected]>
I'm trying to develop a JAXP implementation using CNI, but I get a 
NullPointerException when I try to get a DOMImplementation.  I've 
attached a small script (tested on Ubuntu 9.04) which demonstrates the 
problem.

Any help would be appreciated.

- Sam Ruby
testdomimpl.sh (application/x-sh, 1.9 KB)
#!/bin/sh

cat >testdomimpl.java <<EOF
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;

class testdomimpl {
  public static void main(String[] arg) {

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    System.out.println(factory);
    try {
      DocumentBuilder parser = factory.newDocumentBuilder();
      System.out.println(parser);
      if (parser.getDOMImplementation() != null) {
        System.out.println(parser.getDOMImplementation());
      }
    } catch (java.lang.Throwable ex) {
      ex.printStackTrace();
    }

  }
}
EOF

gcj -o testdomimpl1 --main=testdomimpl testdomimpl.java
./testdomimpl1

mkdir -p headers
gcjh -cp /usr/share/java/jaxp-1.3.jar:/usr/share/java/libgcj.jar -d headers \
  org.w3c.dom.DOMImplementation \
  javax.xml.parsers.DocumentBuilder \
  javax.xml.parsers.DocumentBuilderFactory 

cat >testdomimpl.cpp <<EOF
#include <gcj/cni.h>

#include <java/lang/System.h>
#include <java/lang/Throwable.h>
#include <java/io/PrintStream.h>
#include <org/w3c/dom/DOMImplementation.h>
#include <javax/xml/parsers/DocumentBuilderFactory.h>
#include <javax/xml/parsers/DocumentBuilder.h>

#include <stdio.h>

using namespace java::lang;
using namespace javax::xml::parsers;

int main(int argc, char** argv) {
  JvCreateJavaVM(NULL);
  JvAttachCurrentThread(NULL, NULL);
  JvInitClass(&System::class$);
  JvInitClass(&DocumentBuilderFactory::class$);

  DocumentBuilderFactory *factory = DocumentBuilderFactory::newInstance();
  System::out->println(factory);
  try {
    DocumentBuilder *parser = factory->newDocumentBuilder();
    System::out->println(parser);
    if (parser->getDOMImplementation()) {
      System::out->println(parser->getDOMImplementation());
    }
  } catch (java::lang::Throwable *ex) {
    ex->printStackTrace();
  }
  return 0;
}
EOF

echo
g++ -c -Iheaders -o testdomimpl.o testdomimpl.cpp
gcj -o testdomimpl2 testdomimpl.o
./testdomimpl2
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.