Spontaneous NullPointerExceptions when firing Events - java

I'm currently making a JavaFX Level Editor in combination with the LWJGL library in order to implement OpenGL capabilities, and thus, using multi-threading.
My problem however, is that sometimes when I fire JavaFX events (when I press a button / key etc.) I get this spontaneous java.lang.NullPointerException. I can't seem to figure out the pattern of when exactly the error occurs, and for some strange reason the stacktrace won't provide me with where the exception occurred. All I know is that it occurs when I in some way interact with the JavaFX Application Thread.
When it does occur however, it does not only print it to the console once and then crash. What happens is that the application continuously prints out the the error message over and over again until I force-close the application. It seems like I can no longer fire some specific events when the error has occurred.
This is the spontaneous repeated error message that I get:
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at javafx.scene.Scene$ScenePulseListener.synchronizeSceneNodes(Unknown Source)
at javafx.scene.Scene$ScenePulseListener.pulse(Unknown Source)
at com.sun.javafx.tk.Toolkit.lambda$runPulse$30(Unknown Source)
at com.sun.javafx.tk.Toolkit$$Lambda$153/452428720.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.Toolkit.runPulse(Unknown Source)
at com.sun.javafx.tk.Toolkit.firePulse(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$400(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit$$Lambda$42/424424770.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$145(Unknown Source)
at com.sun.glass.ui.win.WinApplication$$Lambda$38/12064136.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I guess that it has something to do with "synchronizing nodes". Since I'm working with multithreading in order to run a render-loop with OpenGL this might have something to do with the case. I am also using Lambda Expression from Java8, and apparently as it says in the error log it has something to do with them too.
I am not expecting someone to give me an exact answer to what my problem is, and what I've done wrong, since I do not provide any code (because my project is too big and I do not know where the Exception occurs).
However, I have a few generic questions:
What does this error log mean?
What might cause this?
Why does it not provide me with any information of where the Exception occurred?
I managed to get the line numbers from the stacktrace by switching JRE in Eclipse from the JRE installation to the jar provided by the JDK. This allowed me to get line numbers from the compiled APIs, such at JavaFX itself.
This is the new error log:
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at javafx.scene.Scene$ScenePulseListener.synchronizeSceneNodes(Scene.java:2289)
at javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2419)
at com.sun.javafx.tk.Toolkit.lambda$runPulse$30(Toolkit.java:314)
at com.sun.javafx.tk.Toolkit$$Lambda$153/478814140.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.Toolkit.runPulse(Toolkit.java:313)
at com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:340)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:525)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:505)
at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$400(QuantumToolkit.java:334)
at com.sun.javafx.tk.quantum.QuantumToolkit$$Lambda$42/1940618951.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$145(WinApplication.java:101)
at com.sun.glass.ui.win.WinApplication$$Lambda$38/640174177.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
My error lies within the JavaFX classes and probably somewhere within my lambda expression, since the only place where it still says (Unknown Source) is where it also says "lambda". Maybe the stacktrace can't show line numbers in lambdas?
Anyway, this is the line of code that returns a NullPointerException:
if (node.getScene() == Scene.this)
This is within the JavaFX Scene class

Not an answer, only suggestion from troubleshooting a very similar problem - a Swing one.
To avoid any guessing, we should look at the source code - resolve the "unknown source" part.
The stacktrace you provided is lacking line numbers.
This is because, the standard JRE is compiled without any debug information.
Once, I believe at Sun times, one could download a separate distribution aimed at developers with all debugging symbols in place.
That allowed, besides having the exact line numbers, also to set up breakpoints inside the JDK's code.
We could start investigating issues right from there.
If there is no JRE with debug symbols, You can always try compiling your own!
I've once successfully compiled the "src.zip" file, which accompanied the JDK distribution. It wasn't self contained though! There were several parts missing, some Linux specific classes etc. The javac from JDK itself had problems with the file - it ran out of memory all the time. Fortunately, the Eclipse's javac compiler can deal with big codebase and partially compile classes.
Then, I ran my program with the resulting jar (the src.zip compiled with debug symbols) at the bootstrap classpath. Normally, you aren't allowed to modify anything inside "java." and "sun." packages. With bootstrap classpath, you can.
Now, back to Your certain problem: both JavaFX and OpenGL solve multithreading issues, by so called "thread confinement". That means, that everything is forcefully single-threaded. Probably, Your issues arises from the fact, that both javaFx and OpenGL has their separate threads! I'm betting, you did some interaction outside of the JavaFX's EDT. But, it's only a far fetched hypothesis. Try getting the source lines, we could go on from there.
At the time I needed the debug info, I was following the answer from here: debug jdk source can't watch variable what it is
But, all the work might not be needed! I just learned, You could attach the source files itself to the boot classpath, as specified here: https://stackoverflow.com/a/10498425
Update,
So, it seems the "node" reference is null (I doubt that "this" is null).
Next step would identifying the null node and find the exact time where it was added. I'd probably put some breakpoints (or printout statements) at all sensible "addNode" invocations - from your program.
From the source code (I quickly skimmed through http://grepcode.com/file/repo1.maven.org/maven2/net.java.openjfx.backport/openjfx-78-backport/1.8.0-ea-b96.1/javafx/scene/Scene.java#2263 ) it seems, the "null" reference comes from the "dirtyNodes" array".
My best bet normally would be, that you're indirectly calling invoking the addToDirtyNodes ( http://grepcode.com/file/repo1.maven.org/maven2/net.java.openjfx.backport/openjfx-78-backport/1.8.0-ea-b96.1/javafx/scene/Scene.java#503 ) from outside the proper Thread. To my surprise, there is a first line which checks if it's called from the proper one:
Toolkit.getToolkit().checkFxUserThread();
Do You happen to see the line "Not on FX application thread; currentThread = " in your program's output?
Let's just hope, it's not a bug in JavaFX itself.

Don't modify your GUI on a non-GUI thread.
As I don't see your code I'm not sure where exactly you do it, but I had the same issue and it turns out I had passed a GUI object to a class of mine that ran a method on a non-GUI thread that was updating a GUI object. So don't do that.

As said, we also had this problem. It seems to have been caused by updating the UI from within a javafx.concurrent.Service's Task's call() method, although the updates were performed from a lambda handed over to Platform.runLater().
So I moved the UI update code from there to the Service's On-Succeeded/Failed-Handlers where it should have been in the first place. That seems to have eliminated the issue for us.

There are two JDK Bug entries related to this:
https://bugs.openjdk.java.net/browse/JDK-8095034
https://bugs.openjdk.java.net/browse/JDK-8098064
Any JDK version before 8u20 may be affected by this problem.

Related

Exception in VOCE sample C++ app

I've been playing around with the C++ api of Voce for speech recognition in one of my projects. So far, I've been able to compile the C++ version of one of the sample apps provided by Voce named recognitionTest (provided under the samples directory in voce-0.9.1).
However, when I try running recognitionTest.exe, I hit an IndexOutOfBoundsException (console output is provided below).
[Voce] Java virtual machine created
[Voce] Initializing recognizer. This may take some time...
[Voce] Initialization complete
This is a speech recognition test. Speak digits from 0-9 into the microphone. Speak 'quit' to quit.
Exception in thread "Recognition thread" java.lang.IndexOutOfBoundsException: Index: 110,Size: 109
at java.util.SubList.rangeCheck(Unknown Source)
at java.util.SubList.get(Unknown Source)
at edu.cmu.sphinx.decoder.scorer.ScoreableJob.getFirst(ThreadedAcousticScorer.java:516)
at edu.cmu.sphinx.decoder.scorer.ThreadedAcousticScorer.scoreScoreables(ThreadedAcousticScorer.java:310)
at edu.cmu.sphinx.decoder.scorer.ThreadedAcousticScorer.calculateScores(ThreadedAcousticScorer.java:276)
at edu.cmu.sphinx.decoder.search.SimpleBreadthFirstSearchManager.scoreTokens(SimpleBreadthFirstSearchManager.java:337)
at edu.cmu.sphinx.decoder.search.SimpleBreadthFirstSearchManager.recognize(SimpleBreadthFirstSearchManager.java:258)
at edu.cmu.sphinx.decoder.search.SimpleBreadthFirstSearchManager.recognize(SimpleBreadthFirstSearchManager.java:226)
at edu.cmu.sphinx.decoder.Decoder.decode(Decoder.java:94)
at edu.cmu.sphinx.recognizer.Recognizer.recognize(Recognizer.java:116)
at edu.cmu.sphinx.recognizer.Recognizer.recognize(Recognizer.java:135)
at voce.SpeechRecognizer.run(SpeechRecognizer.java:129)
at java.lang.Thread.run(Unknown Source)
I'm using Windows 8 and 32-bit version of java 1.5.
Question: Has someone encountered a similar error before? The exception seems to be thrown by the underlying cmusphinx library. So, I'm unable to debug the issue.
Any help would be greatly appreciated!
Please let me know if any additional info would be helpful in figuring out the issue.
Thanks in advance!

null pointer exception when programming for android phone from processing IDE

i am relatively new to java programming and programming for android and have been experimenting with android bluetooth comms using the Ketai library for the processing IDE specifically for use with android and tried to run the example program bluetoothcursors.pde that comes with the library but i keep getting the "application has stopped unexpectedly" error and the console indicates a null pointer exception error. The actual output is below:
FATAL EXCEPTION: Animation Thread
java.lang.NullPointerException
at ketai.net.bluetooth.KBluetoothListener.<init>(KBluetoothListener.java:56)
at ketai.net.bluetooth.KetaiBluetooth.start(KetaiBluetooth.java:207)
at processing.test.bluetoothcursors.BluetoothCursors.setup(BluetoothCursors.java:80)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:1019)
However i cant seem to see where the null pointer exception is coming from. I assume the null pointer exception relates to a variable that has not been instantiated properly. I have tried a process of elimination to try and isolate the cause but i get the same error but with slightly different source. I have also posted this question on the processing forum but have not received a reply. I just assumed that since it was part of the examples for the library it would work so maybe the error is being created somewhere else. I have tried other library examples and theses all work fine so i dont think its my setup. I also have other bluetooth programs working on android from processing but these use pure java code and are harder to follow.
I have had a look at some of the similar questions which have been sort-of helpful but i am still stuck.
I have set the correct bluetooth etc permissions and am using android version 2.3.3 and processing version 2.0.
Any help with this is much appreciated.
Cheers.

iSeries JAVA program with RPGLE Interface crashes when processing images

I have made a java program that creates PDF files based to GnuPdf. It runs perfectly when run using native java code (on windows or iSeries QSH), however, when run through an RPGLE interface, the program crashes (at what seems like random intervals) when processing images. I tracked down one of these down to loading an image from a .jar file and removed the call from the code. It worked for a while but is now crashing for images loaded from IFS. Maybe RPGLE is locking the files somehow, and ideas? The code is called from a Service Program.
Here is the stacktrace
java.lang.NullPointerException
at gnu.jpdf.PDFImage.write(PDFImage.java:286)
at gnu.jpdf.PDFOutput.write(PDFOutput.java:114)
at gnu.jpdf.PDFDocument.write(PDFDocument.java:307)
at gnu.jpdf.PDFJob.end(PDFJob.java:182)
at com.mysite.pdf.PdfDocumentStateValid.endDocument(PdfDocumentStateValid.java:657)
at com.mysite.pdf.PdfDocument.endDocument(PdfDocument.java:36)
java.io.IOException: Descriptor not valid.
at java.lang.Throwable.<init>(Throwable.java:196)
at java.lang.Exception.<init>(Exception.java:41)
at java.io.IOException.<init>(IOException.java:40)
at java.io.FileOutputStream.writeBytes(Native Method)
at java.io.FileOutputStream.write(FileOutputStream.java:260)
at java.io.ByteArrayOutputStream.writeTo(ByteArrayOutputStream.java:112)
at gnu.jpdf.PDFOutput.<init>(PDFOutput.java:96)
at gnu.jpdf.PDFDocument.write(PDFDocument.java:302)
at gnu.jpdf.PDFJob.end(PDFJob.java:182)
at java.awt.PrintJob.finalize(PrintJob.java:60)
at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:116)
at java.lang.ref.Finalizer.access$100(Finalizer.java:47)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:193)
Changing my answer here now that I can see the stack trace. The problem happens when you hit native code (native meaning you are basically drilling into OS level or OS custom code).
You are getting an IOException of Descriptor not valid (and by that I'm assuming it means the file descriptor (ie, FileDescriptor). Now the big difference between running it in QShell and running it from RPG is that the Java code invoked from RPG is probably invoked under a different ID and/or privilege level. You may have to make modifications to the iSeries to your program to grant it authority for Java to have the right authorities to do what it needs. (I know you would think that is something the SecurityManager in Java would have picked up...but I know wierd things can happens sometimes when you are using a custom JVM (read IBM's) on a custom OS (i5/OS). You are left to the mercy of the vendor (in this case IBM). Give that a shot (the permissions thing) and see if that solves your problem.
Also...I googled and just found this related to iSeries: https://www-304.ibm.com/support/docview.wss?uid=nas379538999e744aad1862575b0006e28ab
So it might be that the jt400 library used by the OS may have a flaw and you may need to PTF it and/or your JVM too. Just another thought of something to try.

How to run a java program using eclim?

I can't seem to run a simple Hello World program using eclim. I followed the install guide at http://eclim.org/guides/install.html#guides-install and the tutorial at http://eclim.org/gettingstarted.html#gettingstarted, but when I try to run the program (using :Java) I get
java.lang.RuntimeException: Required setting 'org.eclim.java.run.mainclass' has not been set.
at org.eclim.plugin.jdt.command.src.JavaCommand.execute(JavaCommand.java:107)
at org.eclim.command.Main.main(Main.java:89)
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:597)
at com.martiansoftware.nailgun.NGSession.run(NGSession.java:334)
And I don't know how to set whatever it says I didn't set. The program successfully compiles, and I can run it regularly in terminal, I am using Ubuntu 9.10, java jdk 1.6, eclim 1.5.4.
Thought I'd add a more satisfying answer since this topic came up on top in a few Google searches I did ...
By calling :Java % the file that is currently edited will be run. See here for more details.
It looks like eclim doesn't have the property set that identifies your application's main class. According to http://eclim.org/vim/java/java.html you should be able to remedy this by setting the org.eclim.java.run.mainclass property of your project (to the fully-qualified name of your application's main class).
EDIT - responding to comment:
I'm not familiar with eclim, but I would expect that since this is a project property, you would set it once and from that point on it should be persisted along with the project.
On the other hand, if you want to have multiple main classes that could be invoked and switch between them, then of course you'll need to provide some kind of extra config. How would you expect eclim to know which one you meant by just typing :Java? There might be some nice syntactic sugar you can use to register multiple classes and invoke them as "java 1", "java 2" etc. - but at the end of the day you will always need some way of distinguishing between which class you're thinking of running.

java.nio.channels.OverlappingFileLockException occurring randomly when attempting to embed applet?

Has anyone ever seen this odd error when attempting to load an applet? I get this in jconsole, although the applet activity is pretty plain. I get this exception after
java.lang.NullPointerException
at sun.plugin.AppletViewer.loadJarFiles(Unknown Source)
It's a 1.6.13 issue. It was a JRE bug.

Categories