CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Posts
    8

    StackOverflow when serializing a XML Document Object to Byte Array.<br>

    workaround: None available. We even tried -oss option with all permissible stack sizes, but
    in vain.

    minusVersion: java version "1.1.8"

    description: java version "1.1.8"

    We are running a CORBA server which parses some xml files, generates a XML
    Document object out of them and serializes it to a byte[], one at a
    time.(Operations are single threaded)
    The XML files are a bit deeply nested and contain around 1000 lines. These files
    are configuration files for other servers. So, when a new Server is added thru
    the GUI (which is Swing/JSP and browser based), the server copies a template
    file( Which is about 50 lines of XML) to a new file, parses the new file , gets
    the XML document object out of it, and tries to serialize it to a byte[]. This
    is where StackOverflow exception is thrown and it is thrown from writeObject()
    method. If the server is restarted, it successfully parses all the existing
    file (any number) and all corresponding documents as successfully serialized.
    But again if a new request to add server comes, StackOverFlow is encountered. We
    are using IBM XML Parser(org.w3c.dom.*). We can't move to JDK1.2 because of
    compatibility reasons with VisiBroker(The ORB which we are using). We tried all
    alternatives, code reviews at our best level but the problem remains. As this
    has hampered the whole product release any quick help will be appreciated. I am
    attaching the relevant code :

    ***********************************************
    CODE that produces the above mentioned bug
    ***********************************************
    [&lt;javacode&gt;]
    public byte[] getComponentConfiguration(String type, String instanceId) throws DocNotFoundException, DocFormatException
    {
    String objectId=type+"."+instanceId;
    String filePath=null;
    byte[] serializedDoc=null;

    trace("In getComponentConfiguration");
    try
    {
    return getFromCache(objectId);
    }
    catch(DocNotFoundException e)
    {
    trace("Doc Not found exception thrown for "+objectId);
    // The doc was not in cache. Could have been added later by the
    admin.
    }
    // what if it was added later ?? Need to get file path from CIC and try
    once

    try
    {
    trace("Attempting another try to get the doc for "+objectId);

    filePath=cicReference.getServerProperty(type,instanceId,XML_FILE_PATH);
    trace("Got the filepath : "+filePath);
    }
    catch(InvalidTypeException e)
    {
    throw new DocNotFoundException("The server "+objectId+" doesnt
    exist.");
    } catch(InvalidInstanceException e)
    {
    throw new DocNotFoundException("The server "+objectId+" doesnt
    exist.");
    }
    //************Relevant CODE Starts here********
    try
    {
    trace("^^^^^^^^^^^^^^^^^^^^^^^ File Path :"+filePath);
    //Parse the file and get org.w3c.dom.Document object..
    Document docu = XMLConfigUtils.getDocument(filePath);
    System.out.println(XMLConfigUtils.getGlobalConfigHashtable(docu));
    //Stackoverflow occurs in This method. Code for //this method is given below

    serializedDoc=XMLConfigUtils.getSerializedDocument(filePath);
    trace("Serialized the doc");
    cacheSerializedDoc(objectId,serializedDoc,false,filePath);
    trace("cached the doc");
    return serializedDoc;
    }
    catch( XMLFileNotFoundException e)
    {
    throw new DocNotFoundException("The Config file for this server was
    not found");
    }
    catch(XMLFormatException e)
    {
    throw new DocFormatException("XML format of the config doc is
    erroneous");
    }
    catch(UnableToSyncByteArrayException e)
    {
    throw new DocNotFoundException(e.message);
    }


    }
    //***************************************************************************
    // Code for XMLConfigUtils.getSerializedDocument(filePath).....

    public static byte [] getSerializedDocument(String filename) throws
    XMLFileNotFoundException, XMLFormatException
    {
    if(filename == null || filename.equals(""))
    {
    System.out.println("file name passed is null");
    throw new XMLFileNotFoundException("file name passed is null");
    }
    Document doc= getDocument(filename);
    System.out.println("Got the doc "+doc);
    /***Failure occurs at this step. The same code //works without problem when server is restarting. //(While restarting, //server parses all
    //available XML files including this new one and //byte[]'s of all of them are successfully //prepared. Failure occurs with same code if //new server is added at runtime.

    byte [] ret = serializeDocument(doc);
    System.out.println("Byte arra = "+ret);
    if(ret == null)
    throw new XMLFormatException(" failed");

    return ret;

    }
    //*****Code for serializeDocument(doc)........
    public static byte [] serializeDocument(Document xmlDoc)
    {
    try{
    ByteArrayOutputStream bArray = new ByteArrayOutputStream();
    ObjectOutputStream oStream = new ObjectOutputStream(bArray);
    oStream.writeObject(xmlDoc);
    oStream.close();
    System.out.println("Before close in serializedDocument");
    return bArray.toByteArray();
    }catch(Throwable e)
    {
    e.printStackTrace();
    return null;
    }

    }
    [&lt;/javacode&gt;]

    OSversion: sol2.5.1

    user_type: E

    subcategory: runtime

    synopsis: StackOverflow when serializing a XML Document Object to Byte Array.

    severity: 1

    hardware: sun4

    user_role: D

    comments: (company - Wipro Technologies , email - [email protected])


    dateCreated: May 3, 2000 3:40:44 AM

    jdcid: pugsy

    category: java

    type: bug

    release: 1.1.8





  2. #2
    Join Date
    Jul 2006
    Posts
    1

    Re: StackOverflow when serializing a XML Document Object to Byte Array.<br>

    Hi ParagW,

    I have been facing the same problem with yours.

    Did you solve it? Would you mind to tell me your solution?

    Thanks in any soon advance.

    SB

  3. #3
    Join Date
    Apr 2006
    Location
    India
    Posts
    214

    Re: StackOverflow when serializing a XML Document Object to Byte Array.<br>

    Few questions :

    1. What parser are you using (seems like DOM but not very clear from given code) . If you are using DOM parser and dont have much control over XML file size then sooner or later you are going to hit memory related errors , by the way 50 lines isnt too big to cause such errors. Suggestion try SAX parser.
    2. How is the bytearray returnd thru your static method used (do you ever return that object to gc , meaning ever remove all references to it ?) If you keep references to all such byte arrays for use then you are ending up using all available heap and thats gonna cause an exception soon.

    We have been parsing much bigger XML's but used SAX parser for the same.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured