aspose file tools*
The moose likes Java in General and the fly likes a very elusive bug Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "a very elusive bug" Watch "a very elusive bug" New topic
Author

a very elusive bug

Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4339
    
    2

this has been bothering me for some time now. it seems impossible. it is a solve the maze problem. it solves the maze ok, but if it has to go down a dead end and that dead end branches, then the bug rears it's ugly head. as it goes down the path it turns the icons from wood to fire. if a dead end, it turns them back to wood. except for the one at the spot where the branch occurs. it stays fire. i will post all the code, but i can't post the image files(maybe you can find some to try it out). the problem is in the maze class. i just posted the welcome class so you can run it if you want. in particular look at the final else clause in actionPerformed(), that is where the icon gets set back to wood and the stack gets popped. the problem ONLY occurs if the dead end branches, which is a clue i guess.

and


SCJP
Visit my download page
Neil Cartmell
Ranch Hand

Joined: Feb 13, 2010
Posts: 150
I think i've solved it! Not a hundred percent sure why it works now. But I saw something a bit odd in your code and changed it and it seems to work now. I'll be back to explain in more detail and show you my code.I had taken a photo of a route that caused the bug and now that exact same path works correctly. I just want to do more testing. I'm scared after all that someone will come and beat me to it so I had to post this. haha
Neil Cartmell
Ranch Hand

Joined: Feb 13, 2010
Posts: 150


Ok you can see where I have commented out the code I've changed so you can see what is new. The first thing weird I noticed is you call the current.setEnabled(false) method even though it should already be disabled as any square you move to is disabled in the move() method. So as far as I understand is that current's position is always represented by a Point object at the top of the stack. But in your code you popped it from the stack and set the current again to that Point objects row and column. But really I think you meant to make the current be in the position of the Point that is NOW at the top of the stack. So after popping, I use the peek() method to get the Point at the top of the stack and locate the current by using that position.

I'm sure you understand that was hard to explain, so sorry if that made no sense! Feel free to ask questions. Let me know if you still get the bug. Maybe I've just made a complete fool of myself. I've never debugged anyone elses code before. It seems it is much harder than debugging my own!
Neil Cartmell
Ranch Hand

Joined: Feb 13, 2010
Posts: 150
Also I think you have your "try west" and "try east" comments mixed up.
Neil Cartmell
Ranch Hand

Joined: Feb 13, 2010
Posts: 150
Hi me again. You'll be sick of me by now but I've still been messing about with your program. Although my code works and has fixed your bug, it now will cause an exception if the user presses the solve button when there is no solution. That's easily fixed, but just thought I would point it out.
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4339
    
    2

thanks Niel

yeah i knew i didn't have to disable it there but i was desperate to fix the bug. i will spend more time looking at your solution. doesn't it figure another bug would turn up?

Also I think you have your "try west" and "try east" comments mixed up.

you know how it is with homework assignments
anyway this was a homework from 2004. i'm kind of surprised the professor didn't find them(i didn't mention i already solved one bug i found in it). but then he was pretty busy i suppose.

It seems it is much harder than debugging my own!

try waiting 7 years to do it. you will find your own code is hard to debug also. thanks again
Neil Cartmell
Ranch Hand

Joined: Feb 13, 2010
Posts: 150
Randall Twede wrote:thanks Niel

doesn't it figure another bug would turn up?



This one is dead simple to fix. Just make sure that your code only calls the peek() method when the stack isn't empty.

And it's NEIL not NIEL!

Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4339
    
    2

oops my bad Neil. anyway thanks again for the help.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: a very elusive bug
 
Similar Threads
Thumbnail inside JTable
need help with logic error
JScrollPane within JTable cell issue
Maze Solving
JToggleButton and ImageIcon