File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes require another set of eyes to look at my code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "require another set of eyes to look at my code" Watch "require another set of eyes to look at my code" New topic
Author

require another set of eyes to look at my code

Alan Shiers
Ranch Hand

Joined: Sep 24, 2003
Posts: 237
Hi Guys,

I'm having one of those "Can't see the forest for the trees" moments. I need someone to point out the error of my ways. I'm reading in a ZIP file which contains four files:
  • keygen_1.0.jar
  • pnskeywords.dat
  • keygendep.jar
  • pns_plugin.xml


  • I'm reading in the last one named pns_plugin.xml. It looks like this:


    I am working with two classes: PluginEntry and PluginHandler. See classes below. When I run the following code:



    Note the iteration over the ArrayList. When this prints out it looks like this:

    PluginEntries:
    Name: keygendep.jar Destination Folder: C:\PNS_1.0\ZipInstaller\lib
    Name: keygendep.jar Destination Folder: C:\PNS_1.0\ZipInstaller\lib
    Name: keygendep.jar Destination Folder: C:\PNS_1.0\ZipInstaller\lib

    It should look like this:

    PluginEntries:
    Name: keygen_1.0.jar Destination Folder: C:\PNS_1.0\ZipInstaller\plugins
    Name: pnskeywords.dat Destination Folder: C:\PNS_1.0\ZipInstaller
    Name: keygendep.jar Destination Folder: C:\PNS_1.0\ZipInstaller\lib

    What this tells me is that keygendep.jar is the last element read in from the xml file and when class PluginHandler adds each new PluginEntry to the ArrayList, it is overwriting all the elements in the list with the same last element information. I can't figure out why that is? I've gone over the code in DEBUG mode in Eclipse but nothing jumps out at me as to what is going wrong. The println statements tell the tale in the character() method. Everytime I create a new instance of PluginEntry, I also print out the values of the previous PluginEntry from the ArrayList. The previous one is definitely being overwritten. The problem must lie in the PluginHandler class somehow. Please advise.

    Alan

    Paul Clapham
    Bartender

    Joined: Oct 14, 2005
    Posts: 18570
        
        8

    Alan Shiers wrote:when class PluginHandler adds a new PluginEntry to the ArrayList it is overwriting all the elements in the list with the same last element information.


    As soon as I saw this I knew I was searching for the word "static". And sure enough, your class-level variables in PluginEntry are declared static. So all PluginEntry instances share the same value of name and destination folder.
    Alan Shiers
    Ranch Hand

    Joined: Sep 24, 2003
    Posts: 237
    Damn your good! You were right. I got rid of the "static" declarations in PluginEntry. It worked fine after that. Lesson learned.

    Thanks,

    Alan
     
    GeeCON Prague 2014
     
    subject: require another set of eyes to look at my code