Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem using java.util.Stack with SAX

 
Chilkosae Cozea
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Can it be possible the java.util.Stack empty() function is not returning the correct value.
The probelm is sometime I'm getting java.util.EmptyStackException from poppinout funtion even if I check stack.empty() before calling stack.pop function.

I'm using org.xml.sax.ContentHandler to fetch the first 500 character until the first period(".") in the XML. The code look something like this.

I have this condition in popingout function,.



 
Paul Clapham
Sheriff
Pie
Posts: 20764
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you'll find your error is the obvious one: you are popping from the stack more than you are pushing onto it.

By the way, if you want people to read your code, you should post it inside the "code" tags. I have to say I didn't read the code you posted; unindented code is too hard to read. You can edit your post by clicking on the "Edit" button.
 
Chilkosae Cozea
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul
Thanks for your reply.

Sorry for posting the unformatted code. I was not aware of the standard practise of putting the code in this editor.

As you said I'm popping from the stack more than pushing onto it, does that mean the if condition I put "stack.empty()" before calling the Pop function is not working? In all the scenario where I'm popping out I have put the if condition to check whether stack is empty or not.
 
Chilkosae Cozea
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any updates ???
 
Carey Evans
Ranch Hand
Posts: 225
Debian Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The simple answer is that Stack.empty() won't be returning incorrect values. You haven't included a standalone test case to reproduce your problem so we can't offer much more help. The only reason I can think for for pop() to fail after empty() returns false is if the stack is shared by multiple threads.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You appear to be throwing away the information that can help you. I refer to:



Gee, do you think an IOException might be important enough to print a stack trace

Bill
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic