« Return to Thread: Java subclasses in Ruby

Re: Java subclasses in Ruby

by backspaces :: Rate this Message:

Reply to Author | View in Thread

OK, I looked into the Processing problem.  Several points of interest.

1 - The init() call in PApplet, which does things like launch a thread for animation, performs a test to see if the PApplet is really an applet, or is being used as a panel within an application.  The test looks like:
try {
  getAppletContext();
  online = true;
} catch (NullPointerException e) {
  online = false;
}
The online flag is used within the rest of the library to know how the PApplet/panel is being used.

2 - But the getAppletContext() call does not advertise throwing an exception.  I don't know if that would impact JRuby's java integration subsystem.  The method signature is simply:
  public AppletContext getAppletContext()
.. the return value is simply ignored by Processing .. for good reason, see next:

3 - The code that fails in getAppletContext() is:
public AppletContext getAppletContext() {
  return stub.getAppletContext(); <-- line 181
}
.. which causes the exception to occur:
java.lang.NullPointerException
        at java.applet.Applet.getAppletContext(Applet.java:181)
.. I.e. the stub is not set, thus signals the use of PApplet as a panel, not a true applet.

I can probably figure out a reasonable work around, but for now wanted to report what the problem is.  Possibly JRuby only is aware of advertised exceptions, for example.

Owen

Charles Oliver Nutter-2 wrote:
backspaces wrote:
> Just a quick pointer to a parallel discussion on the Processing board to see
> if I'm understanding Processing's internals correctly:
>   http://tinyurl.com/32hewk
>
> It includes a pointer to the ruby file, and a test without subclassing, just
> calling PApplet directly .. which did not have the exception problem.  This
> leads me to think exception handling works ok in the java classes, but not
> in a subclass of such a class.  I think.  
>
> But no worries for now, let me dig a bit deeper.
>
> Thanks for your patience.

Ok, sounds like good progress so far Owen. Let us know what you find.
That NPE is almost certainly a bug somewhere, but I'm not sure whether
it would be us or processing or your code or what. But the general
structure of what you want to do appears to be working correctly, so
that's great!

- Charlie

 « Return to Thread: Java subclasses in Ruby