Anylogic NullPointer Jar file has no attachment - java

My road traffic model is throwing null pointers with a very cryptic stacktrace:
Exception during discrete event execution:
NullPointerException
java.lang.NullPointerException
at com.anylogic.libraries.road.Car_xjal.g(Unknown Source)
at com.anylogic.libraries.road.Car_xjal.al(Unknown Source)
at com.anylogic.libraries.road.Car_xjal.a(Unknown Source)
at com.anylogic.libraries.road.Car_xjal.on_SegmentEndEvent_xjal(Unknown Source)
at com.anylogic.libraries.road.Car_xjal$SegmentEndEvent.execute(Unknown Source)
at com.anylogic.engine.Engine.n(Unknown Source)
at com.anylogic.engine.Engine.cl(Unknown Source)
at com.anylogic.engine.Engine$n.run(Unknown Source)
The null pointer also doesn't happen immediately, I am able to see the model run for varying lengths of time(60-800 model seconds).
When a breakpoint is created, it says the following:
The JAR file C:\Program Files\AnyLogic 8.8 Professional\plugins\com.anylogic.road_traffic_library_8.8.1.202210270952\lib\RoadTrafficLibrary.jar
has no source attachment. You can attach a source by clicking Attach Source below
It also occasionally throws the same error, but citing a different path("C:\Program Files\AnyLogic 8.8 Professional\jre\lib\jrt-fs.jar") as having no source attachment instead.
Any help is appreciated.

Related

Anylogic NullPointer Exception Process Modeling Blocks

I have created a very simple model in AnyLogic consisting of source, Service, sink and resourcepool blocks. The source is connected to service which is then connected to sink. The source block generates agents of type 1 and resourcepool has agent type 2. When I run the model, I am getting following runtime error. There are no attributes to both the agent types. Also, agent types are created and not population.
java.lang.NullPointerException
at com.anylogic.engine.Port.connect(Unknown Source)
at com.anylogic.libraries.processmodeling.Seize.doCreate(Unknown Source)
at com.anylogic.engine.Agent.createAsEmbedded(Unknown Source)
at com.anylogic.libraries.processmodeling.Service.doCreate(Unknown Source)
at com.anylogic.engine.Agent.createAsEmbedded(Unknown Source)
at model.Main.doCreate(Main.java.619)
at com.anylogic.engine.Agent.createAsEmbedded(Unknown Source)
at com.anylogic.engine.Agent.create(Unknown Source)
at com.anylogic.engine.Engine.start(Unknown Source)
I tried debugging the model but no success and also verified that all the initializations are not null.
Model:
enter image description here
Source properties:
enter image description here
Service properties:
enter image description here
Resourcepool properties:
enter image description here

Catching Exceptions in lambda expressions

I have the simplest code using Files.walk:
Stream<Path> stream = Files.walk(Paths.get("C:\\"));
stream.forEach(f -> {
System.out.println(f);
});
This code throws
Exception in thread "main" java.io.UncheckedIOException: java.nio.file.AccessDeniedException: C:\Documents and Settings
at java.nio.file.FileTreeIterator.fetchNextIfNeeded(Unknown Source)
at java.nio.file.FileTreeIterator.hasNext(Unknown Source)
at java.util.Iterator.forEachRemaining(Unknown Source)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining (Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential (Unknown Source)
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.forEach(Unknown Source)
at devl.test.FindDuplicates.main(FindDuplicates.java:53)
Caused by: java.nio.file.AccessDeniedException: C:\Documents and Settings
at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsDirectoryStream.<init>(Unknown Source)
at sun.nio.fs.WindowsFileSystemProvider.newDirectoryStream (Unknown Source)
at java.nio.file.Files.newDirectoryStream(Unknown Source)
at java.nio.file.FileTreeWalker.visit(Unknown Source)
at java.nio.file.FileTreeWalker.next(Unknown Source)
... 11 more
And the stacktrace points to stream.forEach(f -> {. Adding a try/catch before the code makes it to stop reading the files when the exception is thrown.
The thing is - I want the code to continue reading different files on drive C even though the exception is thrown.
It seems like somehow adding a try/catch inside the foreach would solve it - how do I do it (a try/catch on f -> {, not the System.out.println(f);)?
Please note that I tried to circumvent this by doing
Stream<Path> s = stream.filter(f -> !f.toFile().getAbsolutePath().contains("Documents and Setting"));
s.forEach(f -> {
But the same exception is thrown (even doing stream.filter(f -> false) fails).
EDIT: Please note that I don't want to re-throw an exception (like I was suggested). So using s.forEach(LambdaExceptionUtil.rethrowConsumer(System.out::println)) still fails with the exact stacktrace.
To ignore errors during recursive directory traversal you need to use walkFileTree with a FileVisitor that does error handling.
The stream based convenience wrappers (walk) simply terminate on the first error they encounter, you can't prevent that.
If the listing of directories is what you're after, then why not use DirectoryStreamPaths instead? See the doc here for more: https://docs.oracle.com/javase/7/docs/api/java/nio/file/DirectoryStream.html
Furthere you can use it in conjuction with Java8 and what's more the exception handling is quite good.

gridsim-Exception in thread "router2" java.lang.NullPointerException

I'm working on gridsim Min-Min project for workflow in Java Netbeans,i have 3 entities:user,broker and GridResources.
user send application with form of workfllow to broker
broker send gridlets to GridResource;
i implement the network topology for this entities with helping of example "auction" in example folder of Gridsim's pakage.
when run my programe,sometime its run without error and every thing is ok,
but after 3 run or some time after 8 run its failed with error and stop.
i checked network topology with another example but the logic of my programe is ok but im confiusing with this,i searched but not found anything.
anyone help me?
Exception in thread "router1" java.lang.NullPointerException
at gridsim.net.RIPRouter.dequeue(Unknown Source)
at gridsim.net.RIPRouter.processInternalEvent(Unknown `enter code here`Source)
at gridsim.net.RIPRouter.processEvent(Unknown Source)
at gridsim.net.Router.body(Unknown Source)
at eduni.simjava.Sim_entity.run(Sim_entity.java:605)
Exception in thread "router2" java.lang.NullPointerException
at gridsim.net.RIPRouter.dequeue(Unknown Source)
at gridsim.net.RIPRouter.processInternalEvent(Unknown Source)
at gridsim.net.RIPRouter.processEvent(Unknown Source)
at gridsim.net.Router.body(Unknown Source)
at eduni.simjava.Sim_entity.run(Sim_entity.java:605)

NullPointerException when using JavaFX

I am facing a NullPointerException and I can't figure out where or why it occurs. I'm using JavaFX for a project, and it contains a .fxml file which has lots of components (mostly SVGPaths, Circle objects and Text objects). They are imported into a Controller class. Each SVGPath has a mouse listener (for click, enter and exit actions) and sometimes I get a NullPointerException that makes me crazy because I have spent hours trying to solve it. Here is the exact stack trace of exception.
java.lang.NullPointerException
at com.sun.javafx.sg.prism.NGTextHelper.computeBoundsLogical(Unknown Source)
at com.sun.javafx.sg.prism.NGTextHelper.computeContentBounds(Unknown Source)
at javafx.scene.text.Text.impl_computeGeomBounds(Unknown Source)
at javafx.scene.Node.updateGeomBounds(Unknown Source)
at javafx.scene.Node.getGeomBounds(Unknown Source)
at javafx.scene.Node.getLocalBounds(Unknown Source)
at javafx.scene.Node$MiscProperties$2.computeBounds(Unknown Source)
at javafx.scene.Node$LazyBoundsProperty.get(Unknown Source)
at javafx.scene.Node$LazyBoundsProperty.get(Unknown Source)
at javafx.scene.Node.getBoundsInLocal(Unknown Source)
at com.sun.javafx.scene.control.skin.TextAreaSkin$ContentView.layoutChildren(Unknown Source)
at javafx.scene.Parent.layout(Unknown Source)
at javafx.scene.Parent.layout(Unknown Source)
at javafx.scene.Parent.layout(Unknown Source)
at javafx.scene.Scene.layoutDirtyRoots(Unknown Source)
at javafx.scene.Scene.doLayoutPass(Unknown Source)
at javafx.scene.Scene.access$3900(Unknown Source)
at javafx.scene.Scene$ScenePulseListener.pulse(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$9.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(Unknown Source)
at com.sun.glass.ui.win.WinApplication$3$1.run(Unknown Source)
at java.lang.Thread.run(Thread.java:722)
I will appreciate it a lot if someone can help and also explain the reason of this occurrence.
Probably you already solved this, but maybe my solution will help others.
If you are working with JavaFX in a Swing Application you have to be careful to only execute JavaFX code in the correspondent thread and to run Swing code only in the EDT.
I was having a similar problem in my application and it was due to the execution of JavaFX code in the EDT. So, to correct this, I reviewed the code to ensure the use of Platform.runLater(...) on methods that were possibly called from the EDT.
Platform.runLater(new Runnable() {
#Override
public void run() {
// JavaFX manipulation code.
}
}
This seems easy but can be tricky to remember sometimes. So, to be sure, review your JavaFX code searching for public methods and interfaces that can be invoked by Swing components and events.

Java: Prevent NPE in MetalFileChooserUI$IndentIcon.getIconWidth?

on Windows systems. I get the following NPE with the FileChooser. It is a known bug that is not fixed by sun yet. http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6342301
Does somebody know a workaround to prevent this exception?
Thanks.
André
Exception in thread "AWT-EventQueue-2" java.lang.NullPointerException
at
javax.swing.plaf.metal.MetalFileChooserUI$IndentIcon.getIconWidth(Unknown
Source) at javax.swing.SwingUtilities.layoutCompoundLabelImpl(Unknown
Source) at javax.swing.SwingUtilities.layoutCompoundLabel(Unknown
Source) at javax.swing.plaf.basic.BasicLabelUI.layoutCL(Unknown
Source) at
javax.swing.plaf.basic.BasicLabelUI.getPreferredSize(Unknown Source)
at javax.swing.JComponent.getPreferredSize(Unknown Source) at
javax.swing.plaf.basic.BasicListUI.updateLayoutState(Unknown Source)
at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(Unknown
Source) at
javax.swing.plaf.basic.BasicListUI$Handler.valueChanged(Unknown
Source) at
javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown
Source) at
javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
at javax.swing.DefaultListSelectionModel.changeSelection(Unknown
Source) at
javax.swing.DefaultListSelectionModel.changeSelection(Unknown Source)
at javax.swing.DefaultListSelectionModel.setSelectionInterval(Unknown
Source) at javax.swing.JList.setSelectedIndex(Unknown Source) at
javax.swing.plaf.basic.BasicComboPopup.setListSelection(Unknown
Source) at javax.swing.plaf.basic.BasicComboPopup.access$300(Unknown
Source) at
javax.swing.plaf.basic.BasicComboPopup$Handler.itemStateChanged(Unknown
Source) at javax.swing.JComboBox.fireItemStateChanged(Unknown Source)
at javax.swing.JComboBox.selectedItemChanged(Unknown Source) at
javax.swing.JComboBox.contentsChanged(Unknown Source)
In the bug report that you linked to, they also mention a workaround.
It seems to come down to calling the methods in a specific order.
Have you tried that?
A DESCRIPTION OF THE PROBLEM :
There appears to be an undocumented bad intereaction between
explicitely setting the UI and removing all file filters, even temporarily.
If the latter is done before setting the ui, trying to display a file dialog
will throw an exception but not if the ui was set prior to messing with
the filters. Maybe it is possible to make the code more robust against
this or to include a warning in the docs?
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached program: it will not bomb. Then move the setUI
line to the bottom of the constructor and try again: it will.
So, now with registered account :)
The problem with these steps in the mentioned link is, that the look and feel and therefor the UI is set globaly in our software. So the UI is set before I'm able to manipulate the file filters.
Edit: Missunderstood the code for reproduction. The exampled works as mentioned. Thanks.
It looks like the workaround description says you should try to set the UI before manipulating the filters. Does this not work?
If that doesn't work, is it possible to create an instance of your manipulated FileFilters at the same point that you are setting your UI?

Categories