[Qt-jambi-interest] NullPointerException under TestNG

Mathias listo.mathias at googlemail.com
Sun Feb 8 17:28:26 CET 2009


Gentlemen,

I'm getting a strange crash when instantiating a QAbstractItemModel sub
class when running a TestNG test.
Consider this short code example:

import com.trolltech.qt.QtBlockedSlot;
import com.trolltech.qt.core.QAbstractItemModel;
import com.trolltech.qt.core.QModelIndex;
import org.testng.annotations.Test;

public class SimpleTest {

    public static class MyModel extends QAbstractItemModel {
        @QtBlockedSlot
        public int columnCount(QModelIndex index) { return 0; }

        @QtBlockedSlot
        public Object data(QModelIndex index, int i) { return null; }

        @QtBlockedSlot
        public QModelIndex index(int i, int i1, QModelIndex index) { return
null; }

        @QtBlockedSlot
        public QModelIndex parent(QModelIndex index) { return null; }

        @QtBlockedSlot
        public int rowCount(QModelIndex index) { return 0; }
    }

    @Test
    public void test() {
        System.out.println(new MyModel());
    }

    public static void main(String[] args) {
        System.out.println(new MyModel());
    }

}


When running the static main() method everything works fine, output is
something like this:
test::SimpleTest$MyModel(0x31c92d8)

However, when I run the TestNG test using a TestNG test runner the thing
crashes somewhere inside the QAbstractItemModel constructor:

java.lang.NullPointerException
    at
com.trolltech.qt.internal.MetaObjectTools.buildMetaData(MetaObjectTools.java:787)
    at
com.trolltech.qt.core.QAbstractItemModel.__qt_QAbstractItemModel_QObject(Native
Method)
    at
com.trolltech.qt.core.QAbstractItemModel.<init>(QAbstractItemModel.java:102)
    at
com.trolltech.qt.core.QAbstractItemModel.<init>(QAbstractItemModel.java:98)
    at test.SimpleTest$MyModel.<init>(SimpleTest.java:25)
    at test.SimpleTest.test(SimpleTest.java:44)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:580)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:517)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:669)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:956)
    at
org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:110)
    at org.testng.TestRunner.runWorkers(TestRunner.java:720)
    at org.testng.TestRunner.privateRun(TestRunner.java:590)
    at org.testng.TestRunner.run(TestRunner.java:484)
...

At first I thought it might be a threading problem, but in this example
TestNG runs the test on the main thread...

Does anyone have an idea on what might be causing the problem?
I heavily depend on TestNG for testing my applications and I would hate to
not be able to use it for testing the non-GUI parts of the apps (like the
models).

Cheers,
Mathias
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-jambi-interest/attachments/20090208/d81cb466/attachment.html 


More information about the Qt-jambi-interest mailing list