• Post Reply Bookmark Topic Watch Topic
  • New Topic

How can I fix this from the exception?  RSS feed

 
Paul Ho
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,everyone.

I compiled a java plugin successfully but it threw an exception when I called a function.

1)ERROR

pic1

2)Exception
I detected it in the debug mode on command line.And the exception occurred when call 'run()' function from 'PathfinderPlugin.java:line 79' :

pic2-2

CODE:<PathfinderPlugin.java>


3)source code
According to this exception,I search the source code.
And I think the error may be at either createpath() function itself or its five parameters.

pic3-3

pic4-3
I checked the parameters and the five parameters are not 'null'.So I think the error might be createpath() function itself.

4)source code -> createpath() function
Since the ERROR window shows 'Reson:null'(pic1),I think I need to find this 'null'.
And the createpath() function which is from 'Pathfinder.java' returns 'null' at here(no path exists between the two nodes):

pic6

CODE:<createpath()>


Is this the particular problem(pic6)?
If not,what do I miss and where is the problem?


Thanks for your attention!
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the catch block where the message is posted you have this:

There is a Logger.logException() step. Find where the exception gets logged and read what it says. Hopefully it will be better than the useless 'null' reason that dialog displays. Barring that I would get rid of the entire catch block and let the Thread crash, watching the System.err stream. The JVM will likely provide a much better description of the problem.
 
Paul Ho
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Luke wrote:In the catch block where the message is posted you have this:

There is a Logger.logException() step. Find where the exception gets logged and read what it says. Hopefully it will be better than the useless 'null' reason that dialog displays. Barring that I would get rid of the entire catch block and let the Thread crash, watching the System.err stream. The JVM will likely provide a much better description of the problem.



Thanks!Look up the LOG file.I learn it.
Otherwise,I would be looking the functions one by one

I find the LOG file at last.
<LOG FILE>


I think the problem may be in either checkForComodification or the pathfinding algorithm.
The checkForComodification function is imported from 'java.util'.
The pathfinding algorithm code is written in 'PathFinder.java'.

I thought that I should debug it step by step. But it's not an independent app but a plugin and I may not be qualified in this debugging level.
So I'm not sure this is a good way for me.

Trying to figure out the next step.
 
Paul Ho
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I post the pathfinding algorithm code here if someone would like to have a look.The algorithm is a good one ;)

<PathFinder.java>
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone actually use this code? Has it ever worked? My guess is no. The exception from checkComodification() occurs because you are trying to modify a List as you iterate over it. It should be throwing a ConcurrentModificationException, but the application throws away the useful information. From the stack trace that is provided, I believe the problem is in lines 320 to 326 in the deleteNodesNotOnPath() method:

That code is using an iterator to iterate over the nodes in the view graph. The view.deleteNode() method presumably modifies the list of nodes in the view graph. You can't do that. You need to either:
1) use a ListIterator directly to iterate and use its methods to modify the underlying List. This would work, but would by-pass view.deleteNode() which may have other functionality
2) collect the nodes that are to be deleted into a separate list, and then iterate over the new list and remove them from the view. The problem here is that you iterate the list multiple times, slowing things down.
3) If getNodes() is a List, then you could do view.getGraph().getNodes().retainAll(combined) as a replacement for this entire loop. But again, that by-passes the deleteNode() method which may do other things
4) You could replace the type of the List used so store the nodes by a type guaranteed not to throw ConcurrentModificationExceptions
5) You could modify the getNodes() method to return a copy of the nodes list. This would be slower (traversal of the list twice, once to copy then to search) but is probably the route I would go because it is the safest (forces all methods through the view accessor methods.)
6) Or you could make your own copy of the List that comes from getNodes() and traverse that. It would avoid the error, let you use view.deleteNode(), but would be slower (double iteration) and not have the benefit of protecting the nodes list.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!