I have experienced a null pointer exception when calling g++ from java (using swig generated bindings).
I have made a reduced test case that exhibits the same behaviour which is attached to this report. If I run this on Fedora Core 6 I get: [EMAIL PROTECTED] ~]$ tar -z -x -f java-test.tar.gz [EMAIL PROTECTED] ~]$ cd java-test [EMAIL PROTECTED] java-test]$ ./test.sh Exception in thread "main" java.lang.NullPointerException at test.mytest.Status.getKind(Status.java:45) at test.main(test.java:9) Running on RHEL 4 works: [EMAIL PROTECTED] ~]$ tar -z -x -f java-test.tar.gz [EMAIL PROTECTED] ~]$ cd java-test [EMAIL PROTECTED] java-test]$ ./test.sh OK If I remove the -O2 optimisation flag from the compilation of the C++ code generated by swig as part of the Java binding it works also on FC6: [EMAIL PROTECTED] java-test]$ OPT=no ./test.sh OK My RHEL 4 installation has g++ 3.4.6-8, my FC6 installation has g++ 4.1.2-13. The same behaviour has been seen using Debian/Etch g++ 4.1.1-21. Since removing the -O2 flag makes the code work I suspect this to be an optimisation problem in g++. Since it works with the -O2 flag with the older g++ in RHEL4 this would be a regression. -- Summary: -O2 optimisation causes null pointer exception at runtime when calling g++ from java using jni Product: gcc Version: 4.1.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: mattias dot ellert at tsl dot uu dot se http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33607