
|
If you were logged in you would be able to see more operations.
|
|
|
As discussed in:
http://www.nabble.com/Java-subclasses-in-Ruby-tf3344729.html
we have discovered an improperly handled null pointer exception caused by class Applet .. who's stub is null. Apparently JRuby does not re-wrap the exception in a NPE, thus the Processing library's NPE catch fails to work properly.
In the email:
http://www.nabble.com/Re%3A-Java-subclasses-in-Ruby-p9386203.html
Charlie explains:
Ok, I think I might know what's happening here. Inside JRuby, all
exceptions are RuntimeException, since that's what we pass around.
Exceptions in Java code would get wrapped as a NativeException and
propogated out. My guess is that we're probably not unwrapping and
re-throwing the contained Java exception correctly in these cases.
A complete test case is available, discussed in the mail thread. The test is:
http://backspaces.net/files/rtest.tar.gz
The readme has been a complete explaination, attached.. The simplest test is to simply uncompress rtest.tar.gz, cd to rtest, then do:
export CLASSPATH=. # should only catch stuff in ./processing/core
java RandBoxes # make sure java version still works and prints out messages
jruby testprocessing.rb # test ruby
This results in the desired dump in either java 1.4 or 1.5 Got this trace:
Test: Init() called
Test: Try start
Test: Try exception, e=org.jruby.exceptions.RaiseException: Native Exception: 'class java.lang.NullPointerException'; Message: null; StackTrace: java.lang.NullPointerException
at java.applet.Applet.getAppletContext(Applet.java:181)
at processing.core.PApplet$Proxy0.__super$getAppletContext(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
The complete dump is http://backspaces.net/files/dump
Here's the readme file, with far more details than needed, but may be useful if you need to rebuild processing using 1.4:
- Expand http://backspaces.net/files/rtest.tar.gz
and cd to rtest dir
- To simply test the precompiled versions, this works, both w/ 1.5 and 1.4 java.
export CLASSPATH=. # should only catch stuff in ./processing/core
java RandBoxes # make sure java version still works and prints out messages
jruby testprocessing.rb # test ruby
- Here's the full monty:
- Start clean. Note, I'll reset CLASSPATH several times to make sure we don't
- inadvertently use unexpected classes.
unset CLASSPATH
rm -rf *.class processing testsrc
ls
- Should look like:
- JavaClass.java core.jar testjava.rb
- JavaSubClass.java readme testprocessing.rb
- PAppleTest.java src
- RandBoxes.java testframe.rb
- Note src contains all the processing core source files
- PApplet.java PGraphics3D.java PPolygon.java
- PConstants.java PGraphicsJava2D.java PShape.java
- PFont.java PImage.java PTriangle.java
- PGraphics.java PLine.java
- PGraphics2D.java PMatrix.java
- Switch to using 1.4 just to be sure. (Processing is built on 1.4)
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home
export PATH=$JAVA_HOME/bin:$PATH
java -version
- Simple test to make sure subclassing and NPE works as expected
javac JavaSubClass.java
java JavaSubClass
- Two preliminary jruby tests, one of frames, that we'll use for our Processing test
jruby testframe.rb # make sure frames OK
- .. and one mimicking the JavaSubClass test
export CLASSPATH=. # so jruby sees JavaSubClass
jruby testjava.rb # subclassing and NPE work as expected
- Now build and run the Processing test in Java
export CLASSPATH=core.jar
javac RandBoxes.java
export CLASSPATH=core.jar:.
java RandBoxes
- Now test a ruby version
export CLASSPATH=core.jar
jruby testprocessing.rb
- change line 10 to use PApplet, not RandBoxes. No NPE!
- This works because PApplet in not abstract and uses defaults for size etc
sed 's/RandBoxes.new/PApplet.new/' <testprocessing.rb | jruby
- Here's the jar file contents:
jar tvf core.jar
- 0 Mon Nov 13 18:57:26 MST 2006 processing/
- 0 Thu Nov 30 16:29:44 MST 2006 processing/core/
- 591 Thu Nov 30 17:33:08 MST 2006 processing/core/PApplet$1.class
- 818 Thu Nov 30 17:33:08 MST 2006 processing/core/PApplet$2.class
- 1140 Thu Nov 30 17:33:08 MST 2006 processing/core/PApplet$3.class
- 752 Thu Nov 30 17:33:08 MST 2006 processing/core/PApplet$4.class
- 1064 Thu Nov 30 17:33:08 MST 2006 processing/core/PApplet$5.class
- 487 Thu Nov 30 17:33:08 MST 2006 processing/core/PApplet$6.class
- 490 Thu Nov 30 17:33:08 MST 2006 processing/core/PApplet$7.class
- 535 Thu Nov 30 16:36:18 MST 2006 processing/core/PApplet$8.class
- 1286 Thu Nov 30 17:33:08 MST 2006 processing/core/PApplet$RegisteredMethods.class
- 945 Thu Nov 30 17:33:08 MST 2006 processing/core/PApplet$Worker$1.class
- 2025 Thu Nov 30 17:33:08 MST 2006 processing/core/PApplet$Worker.class
- 499 Thu Nov 30 17:33:08 MST 2006 processing/core/PApplet$WorkerVar.class
- 84537 Thu Nov 30 17:33:08 MST 2006 processing/core/PApplet.class
- 5271 Thu Nov 30 17:33:08 MST 2006 processing/core/PConstants.class
- 10927 Thu Nov 30 17:33:08 MST 2006 processing/core/PFont.class
- 37829 Thu Nov 30 17:33:08 MST 2006 processing/core/PGraphics.class
- 16786 Thu Nov 30 17:33:08 MST 2006 processing/core/PGraphics2D.class
- 37665 Thu Nov 30 17:33:08 MST 2006 processing/core/PGraphics3D.class
- 1898 Thu Nov 30 17:33:10 MST 2006 processing/core/PGraphicsJava2D$ImageCache.class
- 16073 Thu Nov 30 17:33:10 MST 2006 processing/core/PGraphicsJava2D.class
- 23073 Thu Nov 30 17:33:08 MST 2006 processing/core/PImage.class
- 11827 Thu Nov 30 17:33:08 MST 2006 processing/core/PLine.class
- 10391 Thu Nov 30 17:33:08 MST 2006 processing/core/PMatrix.class
- 8824 Thu Nov 30 17:33:08 MST 2006 processing/core/PPolygon.class
- 2972 Thu Nov 30 17:33:10 MST 2006 processing/core/PShape.class
- 27970 Thu Nov 30 17:33:10 MST 2006 processing/core/PTriangle.class
- Now rebuild the processing library from source. Make sure we're still on 1.4
java -version
- make a copy of the src folder and compile it to make sure all is well.
- I get one deprecation warning.
cp -Rp src testsrc
javac -deprecation -d . testsrc/*
- list the resulting classes
ls -R processing
- Note: I get one class not in the jar file: PApplet$Worker$1.class
- Not sure why, but everything works
- Test this vanilla rebuild with RandBoxes.class
export CLASSPATH=. # should only catch stuff in ./processing/core
java RandBoxes # should work as before
- Edit testsrc/PApplet.java to have these changes:
- public void init() {
- System.out.println("Test: Init() called");
- ..
- try {
# System.out.println("Test: Try start");
# getAppletContext();
# System.out.println("Test: Try OK");
# online = true;
# } catch (Exception e) { // NullPointerException
# System.out.println("Test: Try exception, e="+e);
# online = false;
# }
- .. or just copy the one I used:
cp PAppleTest.java testsrc/PApplet.java
- Now rerun with new PApplet
javac -deprecation -d . testsrc/PApplet.java
java RandBoxes # should now report results of try/catch
- Now run ruby test which should catch the exception:
jruby testprocessing.rb # test ruby
|
|
Description
|
As discussed in:
http://www.nabble.com/Java-subclasses-in-Ruby-tf3344729.html
we have discovered an improperly handled null pointer exception caused by class Applet .. who's stub is null. Apparently JRuby does not re-wrap the exception in a NPE, thus the Processing library's NPE catch fails to work properly.
In the email:
http://www.nabble.com/Re%3A-Java-subclasses-in-Ruby-p9386203.html
Charlie explains:
Ok, I think I might know what's happening here. Inside JRuby, all
exceptions are RuntimeException, since that's what we pass around.
Exceptions in Java code would get wrapped as a NativeException and
propogated out. My guess is that we're probably not unwrapping and
re-throwing the contained Java exception correctly in these cases.
A complete test case is available, discussed in the mail thread. The test is:
http://backspaces.net/files/rtest.tar.gz
The readme has been a complete explaination, attached.. The simplest test is to simply uncompress rtest.tar.gz, cd to rtest, then do:
export CLASSPATH=. # should only catch stuff in ./processing/core
java RandBoxes # make sure java version still works and prints out messages
jruby testprocessing.rb # test ruby
This results in the desired dump in either java 1.4 or 1.5 Got this trace:
Test: Init() called
Test: Try start
Test: Try exception, e=org.jruby.exceptions.RaiseException: Native Exception: 'class java.lang.NullPointerException'; Message: null; StackTrace: java.lang.NullPointerException
at java.applet.Applet.getAppletContext(Applet.java:181)
at processing.core.PApplet$Proxy0.__super$getAppletContext(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
The complete dump is http://backspaces.net/files/dump
Here's the readme file, with far more details than needed, but may be useful if you need to rebuild processing using 1.4:
- Expand http://backspaces.net/files/rtest.tar.gz
and cd to rtest dir
- To simply test the precompiled versions, this works, both w/ 1.5 and 1.4 java.
export CLASSPATH=. # should only catch stuff in ./processing/core
java RandBoxes # make sure java version still works and prints out messages
jruby testprocessing.rb # test ruby
- Here's the full monty:
- Start clean. Note, I'll reset CLASSPATH several times to make sure we don't
- inadvertently use unexpected classes.
unset CLASSPATH
rm -rf *.class processing testsrc
ls
- Should look like:
- JavaClass.java core.jar testjava.rb
- JavaSubClass.java readme testprocessing.rb
- PAppleTest.java src
- RandBoxes.java testframe.rb
- Note src contains all the processing core source files
- PApplet.java PGraphics3D.java PPolygon.java
- PConstants.java PGraphicsJava2D.java PShape.java
- PFont.java PImage.java PTriangle.java
- PGraphics.java PLine.java
- PGraphics2D.java PMatrix.java
- Switch to using 1.4 just to be sure. (Processing is built on 1.4)
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home
export PATH=$JAVA_HOME/bin:$PATH
java -version
- Simple test to make sure subclassing and NPE works as expected
javac JavaSubClass.java
java JavaSubClass
- Two preliminary jruby tests, one of frames, that we'll use for our Processing test
jruby testframe.rb # make sure frames OK
- .. and one mimicking the JavaSubClass test
export CLASSPATH=. # so jruby sees JavaSubClass
jruby testjava.rb # subclassing and NPE work as expected
- Now build and run the Processing test in Java
export CLASSPATH=core.jar
javac RandBoxes.java
export CLASSPATH=core.jar:.
java RandBoxes
- Now test a ruby version
export CLASSPATH=core.jar
jruby testprocessing.rb
- change line 10 to use PApplet, not RandBoxes. No NPE!
- This works because PApplet in not abstract and uses defaults for size etc
sed 's/RandBoxes.new/PApplet.new/' <testprocessing.rb | jruby
- Here's the jar file contents:
jar tvf core.jar
- 0 Mon Nov 13 18:57:26 MST 2006 processing/
- 0 Thu Nov 30 16:29:44 MST 2006 processing/core/
- 591 Thu Nov 30 17:33:08 MST 2006 processing/core/PApplet$1.class
- 818 Thu Nov 30 17:33:08 MST 2006 processing/core/PApplet$2.class
- 1140 Thu Nov 30 17:33:08 MST 2006 processing/core/PApplet$3.class
- 752 Thu Nov 30 17:33:08 MST 2006 processing/core/PApplet$4.class
- 1064 Thu Nov 30 17:33:08 MST 2006 processing/core/PApplet$5.class
- 487 Thu Nov 30 17:33:08 MST 2006 processing/core/PApplet$6.class
- 490 Thu Nov 30 17:33:08 MST 2006 processing/core/PApplet$7.class
- 535 Thu Nov 30 16:36:18 MST 2006 processing/core/PApplet$8.class
- 1286 Thu Nov 30 17:33:08 MST 2006 processing/core/PApplet$RegisteredMethods.class
- 945 Thu Nov 30 17:33:08 MST 2006 processing/core/PApplet$Worker$1.class
- 2025 Thu Nov 30 17:33:08 MST 2006 processing/core/PApplet$Worker.class
- 499 Thu Nov 30 17:33:08 MST 2006 processing/core/PApplet$WorkerVar.class
- 84537 Thu Nov 30 17:33:08 MST 2006 processing/core/PApplet.class
- 5271 Thu Nov 30 17:33:08 MST 2006 processing/core/PConstants.class
- 10927 Thu Nov 30 17:33:08 MST 2006 processing/core/PFont.class
- 37829 Thu Nov 30 17:33:08 MST 2006 processing/core/PGraphics.class
- 16786 Thu Nov 30 17:33:08 MST 2006 processing/core/PGraphics2D.class
- 37665 Thu Nov 30 17:33:08 MST 2006 processing/core/PGraphics3D.class
- 1898 Thu Nov 30 17:33:10 MST 2006 processing/core/PGraphicsJava2D$ImageCache.class
- 16073 Thu Nov 30 17:33:10 MST 2006 processing/core/PGraphicsJava2D.class
- 23073 Thu Nov 30 17:33:08 MST 2006 processing/core/PImage.class
- 11827 Thu Nov 30 17:33:08 MST 2006 processing/core/PLine.class
- 10391 Thu Nov 30 17:33:08 MST 2006 processing/core/PMatrix.class
- 8824 Thu Nov 30 17:33:08 MST 2006 processing/core/PPolygon.class
- 2972 Thu Nov 30 17:33:10 MST 2006 processing/core/PShape.class
- 27970 Thu Nov 30 17:33:10 MST 2006 processing/core/PTriangle.class
- Now rebuild the processing library from source. Make sure we're still on 1.4
java -version
- make a copy of the src folder and compile it to make sure all is well.
- I get one deprecation warning.
cp -Rp src testsrc
javac -deprecation -d . testsrc/*
- list the resulting classes
ls -R processing
- Note: I get one class not in the jar file: PApplet$Worker$1.class
- Not sure why, but everything works
- Test this vanilla rebuild with RandBoxes.class
export CLASSPATH=. # should only catch stuff in ./processing/core
java RandBoxes # should work as before
- Edit testsrc/PApplet.java to have these changes:
- public void init() {
- System.out.println("Test: Init() called");
- ..
- try {
# System.out.println("Test: Try start");
# getAppletContext();
# System.out.println("Test: Try OK");
# online = true;
# } catch (Exception e) { // NullPointerException
# System.out.println("Test: Try exception, e="+e);
# online = false;
# }
- .. or just copy the one I used:
cp PAppleTest.java testsrc/PApplet.java
- Now rerun with new PApplet
javac -deprecation -d . testsrc/PApplet.java
java RandBoxes # should now report results of try/catch
- Now run ruby test which should catch the exception:
jruby testprocessing.rb # test ruby
|
Show » |
|