Problem on serialization & Obfuscation

I really need your help, please help me.
I having problem on serialization & Obfuscation. The problem is I get back the blank object that i writen into the file after obfuscated.
I have a class A implements Serializable and using serialVersionUID.
I write the class A object to a file and able to read back the object from the file.
After obfuscation, I can read back the object from the file but the object is blank( no more data ).
Can anyone tell me what is the problem?

Can anyone tell me what is the problem?Yes. There's probably a problem in your code.

Similar Messages

  • Problem with Serialization from Threads

    I'm quite new to java threads, and i'm doing a simple server.
    It opens a thread for every socket connection that is opened, so the Socket is extern to the Thread.
    When I try to serialize on the socket a Vector (that contains Vectors, etc..) that is extern to the Thread, the first time everything goes ok, but when the thread modifies some variables in some objects contained in a vector(that, i repeat is extern to the thread), the serialized object doesn't seem to change, and the client continues receiving the same variables, without change.
    In a first time i thought that maybe creating a thread, the second one took a copy of the space of addresses of the main one(and so when i modify a variable from a thread the variable in the main thread didn't change), but i read that java uses the same space of addresses for every thread, so i don't really know what it could be.
    Maybe i've not been clear so i make an example:
    MyType is a class containing some fields, let's put x and y
    In the class MainClass i have an istance of this class, and also a socket and from here i open a thread of class MyThread
    MyThread modifies x and y in a object of MyType contained in the "3D array" that is in MainClass
    Then from that thread i serialized on the socket (which was been passed by MainClass).
    Well, doing this way the vector that the client receives has always the x and y fields unchanged.
    Please help me, cause i've been thinking all day of what it could be and found nothing on the web.
    Also sorry for my poor english.

    I thought that could be the problem, but it wasn't.
    The client still receives the vector with objects
    unchanged.
    I think the problem is that the thread can only access
    to a copy of the class that contains the vector, and
    so when i send the real one, it isn't changed.not likely. one of the things about threads is that they share everything but local (read: non-Object) data. All objects are accessible to any thread of your application, as long as that thread has a reference to it.

  • The Problem in serialization.

    The serialization issue is a trivial one at the moment. However the threat of a version change is imminent considering the next release of JDK 6 "Mustang" may have considerable improvements especially on the Swing side. Therefore, I strongly encourage you to write your own code to persist the tree data into a file. Such a logic is much preferable as it will over-come the issues with serialization.
    The main problem with a version change is that every serializable class uses a special random number stored in a private static field called serialVersionUID. So when the serializable class is serialized, this number is also persisted to the serialized form.
    When the object is de-serialized, the number is also deserialized. Java checks the de-serialized number against the serialVersionUID field of the class and verifies if the two match. If they do, it means that the deserialized data is in the right format of the class. If they differ, a InvalidClassException is thrown. Every new version of the class changes this unique number. Hence an object serialized with an older version of the class will not be allowed to be de-serialized by a new version of that class and vice-versa.
    This mechanism allows developers to version their new releases and ensures that serialization and deserialization operations remain consistent across multiple-versions and prevent invalid state of the object.

    The serialization issue is a trivial one at the moment. However the threat of a version change is imminent considering the next release of JDK 6 "Mustang" may have considerable improvements especially on the Swing side.Don't make statements like this unless you know what you're talking about. Do you know that Sun's JDK release policies prevent them from doing that in the middle of a release? and that they haven't done such a thing in 13 years? Do you have any actual evidence that they are going to change serialVersionUIDs in the middle of a release?
    Therefore, I strongly encourage you to write your own code to persist the tree data into a file.
    I would strongly encourage developers not to use Serialization on Swing objects at all, which curiously enough is what the Javadoc has been saying for ten years. You should use java.beans.XMLEncoder for this. That's what it is for.
    Such a logic is much preferable as it will over-come the issues with serialization.Home-grown code is never preferable to what is provided in the JDK.
    The main problem with a version change is that every serializable class uses a special random number stored in a private static field called serialVersionUID.That's not a 'problem'. That's part of the solution.
    Every new version of the class changes this unique number.Only if you don't declare your own static final long serialVersionUID.
    This mechanism allows developers to version their new releases and ensures that serialization and deserialization operations remain consistent across multiple-versions and prevent invalid state of the object.Exactly. I suggest you read the Versioning section of the Serialization specification before posting again on this topic, and also read up on Long Term Persistence in Java Beans. You have much of this information back to front, and you don't appear to have heard of either defining your own serialVersionUID or Long Term Persistence.
    And your claim that Sun will change serialVersionUIDs in the middle of Java release 6 is just ludicrous.

  • A problem using serialization and/or not overwritten variables

    I have a problem while writing objects in ObjectOutputStream :
    Here is a simplified version of the program :
    class InDData implements serializable
         private Vector shapeVector = new Vector ();
         public InDData (Vector shapeV)
              this.shapeVector = shapeV;
         public int getShapeVectorSize ()
              return (this.shapeVector.size());
    class InDShape implements serializable
         private Vector points = new Vector();
    // client side
    ObjectOutputStream p = new ObjectOutputStream(new BufferedOutputStream (connection.getOutputStream()));
    InDData objectData = (InDData) vectorObjectsToBeSentThroughNetwork.remove(0);
    System.out.println(objectData.getShapeVectorSize(); //print 1
    p.writeObject(objectData);
    p.flush();
    //server side
    ObjectInputStream in = new ObjectInputStream(new BufferedInputStream (connection.getInputStream()));
    Object oTemp = in.readObject();
    if (oTemp instanceof InDData)
         InDData objectData2 = (InDData) oTemp;
         System.out.println(objectData2.getShapeVectorSize(); //print 2
    Some explanations before the main dish :)
    I am writing a client that allows you to draw a figure and send it to the network. The drawing is composed of shapes and each shape (class InDShape) is composed of points. For the drawing to be sent to the network, i add the shapeVector (== drawing) to the class named InDData (this class allows me to add some more information about the client and the object sent, not shown here) and then i write the object InDData created in the ObjectOutputStream.
    Before writing InDData to the ObjectOutputStream, i test to see if it has a good shapeVector by drawing the shapeVector at the screen. This always shows the same copy as the last drawn panel.
    We suppose that the drawing is sent to the network after each drawn shape
    (mousePressed -> mousseDragged -> mousseReleased)
    (<------------------------------- shape ------------------------------->)
    now the problem ;)
    When i start drawing, the first shape is sent through the network without any problem.
    As soon as i add a second shape to the drawing (shapeVector.size() == 2) things get weird.
    The drawing sent to the network is made only of the first shape, nothing more.
         output of program after the 2nd shape was drawn
         client print 1 : size is 2
         server print 2 : size is 1
    Alright seems like the shapeVector is truncated...
    Now i tried something else to see if the it's only the Vector which is truncated or anything else.
    After adding a second shape to the drawing, i delete the first shape of it:
         reprenstation of the shapeVector:
         ([shape1])
         ([shape1][shape2]) // added the 2nd shape
         ([shape2]) // deleted the first shape
         ([shape2][shape3]) // added a third shape. Vector sent to the network via InDData
         output of program with the vector shown above
         client print 1 : size is 2
         server print 2 : size is 1
    Additionnaly you might expect me to say that first element of shapeVector inside both class InDData (client and server) are the same, but unfortunately they are not.
    The shapeVector received by the server via InDData is the same as when i drew the first shape :((
    Here is the problem (!) :(
    I think that i have a variable that is not overwritten somewhere but i don't know because:
    objectData is overwritten each time a message is sent to the server and has the correct values inside.
    objectData2 is overwritten each time a message is received from clients.
    Sorry for the huge post, but i believe that explanations are necessary ;)
    I am using the 1.4.2 jvm (not tested on others) with Xcode (apple powerbook g4 12").
    Thank you all :)

    Update :)
    In my way of making my program "simple" i forgot an important point in the client side :
    // client side
    ObjectOutputStream p = new ObjectOutputStream(new BufferedOutputStream (connection.getOutputStream()));
    while (connectionNotEnded)
         synchronized (waitingVector)
              try
                   waitingVector.wait();     // the only purpose of the Vector is to make the thread wait until it is interrupted to send InDData
              catch (InterruptedException ie)
                   System.out.println("Thread interrupted");
         InDData objectData = (InDData) vectorObjectsToBeSentThroughNetwork.remove(0);
         System.out.println(objectData.getShapeVectorSize(); //print 1
         p.writeObject(objectData);
         p.flush();
    I need it to explain the solution of my problem.
    when I am creating a client, a thread is created with the above code. It creates the ObjectOutputStream and then wait patiently until said to proceed (Thread.interrupted()).
    I do not close the ObjectOutputStream during the program running time.
    So whenever I am writing an object to the stream, the stream "sees" if the object was created before. I suppose that the ObjectOutputStream has a kind of memory for past written objects.
    So when i send the first InDData, the ObjectOutputStream's memory is "empty", thus the correct sending (and serialization) of InDData.
    But whenever I try to write another object of the same type InDData containing approximately the same data (shapeVector), the ObjectOutputStream calls its "memory" and tries to find it in the past written objects. And finds it in my case ! That's why whatever i put in the shapeVector, it ends by being the first shapeVector sent through the network. (I assume that the recall memory process lacks of "precision" in identifying the memory's object or that the process to give a unique serial to the written object in the ObjectOutputStream "memory" is limited).
    I tried the different ObjectOutputStream writing methods :
    instead of p.writeObject(objectData) i put p.writeUnshared(objectData).
    But as it is said in the docs : " While writing an object via writeUnshared does not in itself guarantee a unique reference to the object when it is deserialized, it allows a single object to be defined multiple times in a stream, so that multiple calls to readUnshared by the receiver will not conflict. Note that the rules described above only apply to the base-level object written with writeUnshared, and not to any transitively referenced sub-objects in the object graph to be serialized."
    And that is exactly my case !
    So i had to take it to the next level :)
    instead of trying to make each written object unique, i simply reset the stream each time it is flushed. That allows me to keep the stream opened and as fresh as new ;) I think the cost of resetting the stream is higher than writeUnshared but lower than closing and creating a new stream each time otherwise it would not have been implemented ;)
    Here is the final code for the client side, the server side remains unchanged :
    // client side
    ObjectOutputStream p = new ObjectOutputStream(new BufferedOutputStream (connection.getOutputStream()));
    while (connectionNotEnded)
         synchronized (waitingVector)
              try
                   waitingVector.wait();     // the only purpose of the Vector is to make the thread wait until it is interrupted to send InDData
              catch (InterruptedException ie)
                   System.out.println("Thread interrupted");
         InDData objectData = (InDData) vectorObjectsToBeSentThroughNetwork.remove(0);
         System.out.println(objectData.getShapeVectorSize(); //print 1
         p.writeObject(objectData);
         p.flush();
         p.reset();
    And that solves my problem :)

  • Problem to serialize using XMLSerializer

    Hi,
    I am getting exception while exucuting the following code:
         private void printToFile(Document dom, String filePath) {
              try {
                   logger.debug("printToFile(): " + filePath);
                   File file = new File(filePath);
                   logger.debug(1);
              OutputFormat format = new OutputFormat(dom);
              logger.debug(2);
              format.setIndenting(true);
              // EncodingInfo encodingInfo=new EncodingInfo();
              format.setEncoding("ISO-8859-1");
              //format.setEncoding(encodingInfo);
              //format.setIndent(100);
              //format.setIndenting(false);
              logger.debug(33);
                   // to generate a file output use fileoutputstream
              XMLSerializer serializer = new XMLSerializer(new FileOutputStream(
                             file), format);
                   logger.debug(44);
              serializer.serialize(dom);
              logger.debug(5);
                   if (format != null)
                        format = null;
                   if (serializer != null)
                        serializer = null;
                   logger.debug(6);
              } catch (IOException ioException) {
              logger.error(ioException, ioException);
    Exception is:
    java.io.IOException: The character '' is an invalid XML character
    java.io.IOException: The character '' is an invalid XML character
         at com.sun.org.apache.xml.internal.serialize.BaseMarkupSerializer.fatalError(BaseMarkupSerializer.java:1873)
         at com.sun.org.apache.xml.internal.serialize.BaseMarkupSerializer.surrogates(BaseMarkupSerializer.java:1542)
         at com.sun.org.apache.xml.internal.serialize.XMLSerializer.printText(XMLSerializer.java:1334)
         at com.sun.org.apache.xml.internal.serialize.BaseMarkupSerializer.characters(BaseMarkupSerializer.java:1383)
         at com.sun.org.apache.xml.internal.serialize.BaseMarkupSerializer.serializeNode(BaseMarkupSerializer.java:1059)
         at com.sun.org.apache.xml.internal.serialize.XMLSerializer.serializeElement(XMLSerializer.java:1089)
         at com.sun.org.apache.xml.internal.serialize.BaseMarkupSerializer.serializeNode(BaseMarkupSerializer.java:1209)
         at com.sun.org.apache.xml.internal.serialize.XMLSerializer.serializeElement(XMLSerializer.java:1089)
         at com.sun.org.apache.xml.internal.serialize.BaseMarkupSerializer.serializeNode(BaseMarkupSerializer.java:1209)
         at com.sun.org.apache.xml.internal.serialize.XMLSerializer.serializeElement(XMLSerializer.java:1089)
         at com.sun.org.apache.xml.internal.serialize.BaseMarkupSerializer.serializeNode(BaseMarkupSerializer.java:1209)
         at com.sun.org.apache.xml.internal.serialize.XMLSerializer.serializeElement(XMLSerializer.java:1089)
         at com.sun.org.apache.xml.internal.serialize.BaseMarkupSerializer.serializeNode(BaseMarkupSerializer.java:1209)
         at com.sun.org.apache.xml.internal.serialize.XMLSerializer.serializeElement(XMLSerializer.java:1089)
         at com.sun.org.apache.xml.internal.serialize.BaseMarkupSerializer.serializeNode(BaseMarkupSerializer.java:1209)
         at com.sun.org.apache.xml.internal.serialize.BaseMarkupSerializer.serializeNode(BaseMarkupSerializer.java:1277)
         at com.sun.org.apache.xml.internal.serialize.BaseMarkupSerializer.serialize(BaseMarkupSerializer.java:489)
         at com.ezemrx.dbfactory.ExportManager.printToFile(Unknown Source)
         at com.ezemrx.dbfactory.ExportManager.exportEncounterHistory(Unknown Source)
         at com.ezemrx.dbfactory.ExportManager.exportHistory(Unknown Source)
         at com.ezemrx.controller.ExportAction.requestToExportAll(Unknown Source)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at uk.ltd.getahead.dwr.impl.ExecuteQuery.execute(ExecuteQuery.java:239)
         at uk.ltd.getahead.dwr.impl.DefaultExecProcessor.handle(DefaultExecProcessor.java:48)
         at uk.ltd.getahead.dwr.impl.DefaultProcessor.handle(DefaultProcessor.java:81)
         at uk.ltd.getahead.dwr.AbstractDWRServlet.doPost(AbstractDWRServlet.java:162)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
         at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
         at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
         at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
         at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
         at java.lang.Thread.run(Thread.java:595)

    this exception occurs because, (in your case) the parent class doesn't have an accessible no-arg constructor.
    the following applies if you have written the parent class.
    you could provide a no-arg constructor. this will take care of the runtime exception. but you will see that after deserialization the member variables defined in the parent class will be set to their default values.
    what you could do is make the parent implement Serializable.
    there is no problem if one of the subclasses is never serialized. The Serializable interface only indicates that the implementing class and its subclasses may be serialized
    hth
    partha

  • Problem in serialization of an element

    Hi,
    I'm facing a problem in sending out message for document style webservice. I have tried to explain the sceanario below as much as possible.
    I'm writing Bpel process to invoke a wsdl . The input variable to the operation has 2 parts - header and body. The problem occurs in serializing the body. I'm writing the relevant portions of the wsdl below:
    Schema:
    <xsd:element name="ReceiveDocument" type="xsd:anyType"/>
    Message:
    <message name="ReceiveDocument_Request">
    <part name="header" element="tns1:XMLGateway_Header" />
    <part name="body" element="tns1:ReceiveDocument"/>
    </message>
    Operation:
    <operation name="ReceiveDocument">
    <input message="tns:ReceiveDocument_Request"/>
    <output message="tns:ReceiveDocument_Response"/>
    </operation>
    In the Bpel process, I have defined the input variable of the type of the following message type:
    <message name="WSPFlowRequestMessage">
    <part name="operation" type="xsd:string"/>
    <part name="target" type="xsd:string"/>
    <part name="header" type="xsd:anyType"/>
    <part name="body" type="xsd:anyType"/>
    </message>
    In the Bpel process my copy rule for assigning the body part is :
    <copy>
    <from variable="inputVariable" part="body"/>
    <to variable="InvokeXMLGw_ReceiveDocument_InputVariable" part="body"/>
    </copy>
    At runtime, I call the Bpel process using Rmi, and below is the body part of the input message passed, as taken from the Audit.
    <part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="body">
    <body>
    <PROCESS_PO_007>
    <CNTROLAREA>
    <BSR>
    <VERB>PROCESS</VERB>
    <NOUN>PO</NOUN>
    <REVISION>007</REVISION>
    </BSR>
    </CNTROLAREA>
    </PROCESS_PO_007>
    </body>
    </part>
    But the problem is that when this body part 's content is sent out on the wire as the input argument of the operation, this is how it looks:
    <ReceiveDocument xmlns="http://xmlns.oracle.com/apps/fnd/XMLGateway">
    <PROCESS_PO_007 xmlns="">< xmlns=""/>
    <CNTROLAREA xmlns="">
    <BSR xmlns="">
    <VERB xmlns="">PROCESS</VERB>
    <NOUN xmlns="">PO</NOUN>
    <REVISION xmlns="">007</REVISION>
    </BSR>
    </CNTROLAREA>
    </PROCESS_PO_007>
    </ReceiveDocument>
    A script enabled browser is required for this page to function properly!
    A script enabled browser is required for this page to function properly!
    Why does this empty xml element occur?
    Please help.
    thanks,
    kannan

    XPath /catalog/book[1]/author/ for author of first book if you don't know the id.
    XSLT related questions, such as XPath usage, are often posted on the mulberry xsl list http://www.mulberrytech.com/xsl/xsl-list/
    You should add a link here from your original thread if you don't want to be accused of cross posting.

  • Problem with Serializable JDO objects containing Hashtables

    Hi,
    I have a simple JDO object which contains a Hashtable and I would like to
    declare as Serializable. It seems though, that whenever I serialize this
    object, I get a NullPointerException. I've written a bare-bones test case
    and reproduced the exception, so I suspect this may be an enhancement issue.
    Thanks,
    Eric
    Exception in thread "main" javax.jdo.JDOException
    NestedThrowables:
    java.lang.NullPointerException
    at
    sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteC
    all.java:245)
    at
    sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:220)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:122)
    at
    org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker_Stub.invoke(Unknown
    Source)
    at
    org.jboss.ejb.plugins.jrmp.interfaces.GenericProxy.invokeContainer(GenericPr
    oxy.java:357)
    at
    org.jboss.ejb.plugins.jrmp.interfaces.StatefulSessionProxy.invoke(StatefulSe
    ssionProxy.java:136)
    at $Proxy1.getHash(Unknown Source)
    at test.HashEjb.getHash(Unknown Source)
    at test.Test.doIt(Test.java:13)
    at test.Test.main(Test.java:7)

    Thanks for the prompt reply Patrick. I can hold off on this until early
    next week...
    "Patrick Linskey" <[email protected]> wrote:
    This is a confirmed bug. We do not correctly deserialize any proxy map
    classes.
    How soon is ASAP? None of us can work on it until later this evening at
    the earliest.
    -Patrick
    Patrick Linskey [email protected]
    SolarMetric Inc. http://www.solarmetric.com

  • I have problem with serializable

    hello i recive de exeption "java.io.NotSerializableException: sun.awt.image.OffScreenImage" and i dont kwon why. if somebody can help me, thanks

    You're getting that exception because that sun.awt.image.OffScreenImage class doesn't implement the Serializable interface.
    Shaun

  • Problems with Serializable

    hello for all
    I am using a class model that this inside of a package (. jar) to access an EJB and when I call a method of the Remote interface the exception is generated:
    Exception executeIncluir Handler: failed to unmarshal cookie; nested exception i:
         java.io.NotSerializableException: model.FaixaDimensional
    But the class FaixaDimensional implements the Serializable class.
    A particularity of model class is that it use it, as a recursive class.
    Please, help me

    I don't think the whole hierarchy has to be serializable because Object is not serializable. Even if your class implements Serializable every one of its instance variables must also implement it or you have to mark them as transient. The error indicates that cookie is not serializable which I don't know if that's true or not.

  • Bussiness object serialization problem

    Hi, I have a little problem with serialization, when I want to create xml from Business object. Example:
    MyBoObject obj = new MyBoObject ();
    obj.atr1 = "aaa";
    obj.atr2 = "bbb";
    String xml = DynamicXml.createXmlTextFor(object : obj, topLevelTag : "something");
    display(xml);
    And displayed result is:
    <something>
    <atr2>bbb</atr2>
    </something>
    atr1 is attribute, which is inherited from db table.
    atr2 is atribute, which I created (it is not inherited from db table)
    Whole problem is, that it only serialize atr2 - from some reason it completely ignores atr1 and his value.
    Like I can't serialize attributes, which are inherited from db table.
    But when I created new attribute atr2 in my Business Object (which is not inherited from db table), everything work ok. Where's the problem? I read docs, but found nothing...
    Edited by: user12189610 on Nov 9, 2009 2:42 AM
    Edited by: user12189610 on Nov 9, 2009 2:46 AM

    If you need a simple project that duplicates this problem for customer support, here's where I put one: http://www.4shared.com/file/181611971/d21e9444/_2__DynamicXMLBug.html.
    Have them import the project, start Studio's Engine, login as "test" and start the Workspace. Create a work item instance and then run the work item when it reaches the "Test" activity. When you run the logic, you'll see this displayed:
    <?xml version="1.0" encoding="UTF-8"?>
    <poHeir xmlns="http://bea.com/albpm/DynamicXml/version/2.0">
        <nameForPO>Dan</nameForPO>
    </poHeir>They should note that only the "nameForPO" tag is created by the DynamicXml.createXmlTextFor() method. "nameForPO" is an attribute I manually added to the XML Heir BPM Object. The attributes of the inherited heir (e.g. "poHeir.orderDate" and "poHeir.billTo") are not included as tags in the generated XML even though these attributes have been set in the logic.

  • Help Needed: Serialization Problem

    I've got a problem with serialization, which is better illustrated with an example (slightly modified version of example in Tech Tips, February 29, 2000, Serialization in the Real World. The problem is that comparing serialized static final fields doesn't return correct result. Any help on how to fix this problem would be greatly appreciated. Thanks in advance. Here is the code:
    ====================
    import java.io.*;
    class Gender implements Serializable {
    String val;
    private Gender(String v) {
    val = v;
    public static final Gender male = new Gender("male");
    public static final Gender female = new Gender("female");
    public String toString() {
    return val;
    public class Person implements Serializable {
    public String firstName;
    public String lastName;
    private String password;
    transient Thread worker;
    public Gender gender;
    public Person(String firstName,
    String lastName,
    String password,
    Gender gender) {
    this.firstName = firstName;
    this.lastName = lastName;
    this.password = password;
    this.gender = gender;
    public boolean isMale() {
    return gender == Gender.male;
    public boolean isFemale() {
    return gender == Gender.female;
    public String toString() {
    return new String(firstName + " " + lastName);
    public static void main(String [] args) {
    Person p = new Person("Fred", "Wesley", "cantguessthis", Gender.male);
    //-NOTE: there ia no problem with this check
    if (p.isMale()) {
    System.out.println("a male: " + p);
    } else if (p.isFemale()) {
    System.out.println("a female: " + p);
    } else System.out.println("strange");
    class WritePerson {
    public static void main(String [] args) {
    Person p = new Person("Fred", "Wesley", "cantguessthis", Gender.male);
    ObjectOutputStream oos = null;
    try {
    oos = new ObjectOutputStream(
    new FileOutputStream(
    "Person.ser"));
    oos.writeObject(p);
    catch (Exception e) {
    e.printStackTrace();
    finally {
    if (oos != null) {
    try {oos.flush();}
    catch (IOException ioe) {}
    try {oos.close();}
    catch (IOException ioe) {}
    class ReadPerson {
    public static void main(String [] args) {
    ObjectInputStream ois = null;
    try {
    ois = new ObjectInputStream(
    new FileInputStream(
    "Person.ser"));
    Person p = (Person)ois.readObject();
    //-NOTE: this is the problem: the check returns false
    if (p.isMale()) {
    System.out.println("a male: " + p);
    } else if (p.isFemale()) {
    System.out.println("a female " + p);
    } else System.out.println("strange");
    catch (Exception e) {
    e.printStackTrace();
    finally {
    if (ois != null) {
    try {ois.close();}
    catch (IOException ioe) {}
    }

    The Gender class implements a type-safe enumeration, but its implementation needs to be improved to ensure that re-creating a Gender object via deserialization doesn't create new objects but uses the existing objects. See this article for details on how that's done:
    http://developer.java.sun.com/developer/Books/shiftintojava/page1.html

  • Obfuscation problem

    I am using wireless tool kit 2.1. I developed an api for accessing web services. It contains some packages with same name of some packages of sun's web service api. Sun's api is already included in the wirelsee tool kit.
    The problem is, When I run the obfuscated jar it gives the following error.
    Uncaught exception java/lang/NoClassDefFoundError: javax/xml/namespace/a: Cannot create class in system package .so I changed the package names to have different names from sun's api package's names. now the obfuscated jar works well.
    What is the reason for this problem. What can I do without changing my package names to run the obfuscated jar.
    But for normal packaging it does't give the above problem. Only obfuscated jar gives problem.

    Thanks for ur reply.
    Yes I got the application work on the phone.
    The problem is I had some packages with standard names including java. , javax. etc. After I changed all the names it works well with the phone.
    But i'm using some already existing classes. so i want to have the original package names. What should i do to to have those packages with original name. It is a must for me.

  • De-serialization not calling default constructor ??

    Hi,
    I have a strange problem with serialization (de-serialization, actually):
    I have a bunch of classes that represent the model for my application.
    These classes are organized as a complex tree and come in three flavors:
    public abstract class AbstractIOCLeaf implements IOCElement {
         private String name;
         private transient boolean changed = false;
         private transient LinkedList<ChangeListener> changeListeners;
         protected AbstractIOCLeaf() {
              super();
              name = null;
              changed = false;
              changeListeners = new LinkedList<ChangeListener>();
         } //needed for Serialzation
         protected AbstractIOCLeaf(String name) {
              this();
              this.name = name;
    ...this class is a leaf: it cannot contain other sub-elements.
    public abstract class AbstractIOCList<T extends IOCElement> extends AbstractIOCNode implements ComboBoxModel {
         protected LinkedList<T> list = null;
         protected transient List<ListDataListener> listListeners;
         protected abstract T newElement(String name);     
         protected AbstractIOCList() { super();  listListeners = new LinkedList<ListDataListener>(); }
         public AbstractIOCList(String name) {
              super(name);
              list = new LinkedList<T>();
              listListeners = new LinkedList<ListDataListener>();
    ... This class holds a list of elements that are all equal.
    and finally:
    public abstract class AbstractIOCNode extends AbstractIOCLeaf implements ChangeListener, ListDataListener {
         protected AbstractIOCNode() { super(); }
         protected AbstractIOCNode(String name) {
              super(name);
    ... This class holds elements that are all different.
    The actual classes extends one of these following the pattern:
    public class StateMachine extends AbstractIOCNode {
         private StateList states = null;;
         private EventQueue fEventQueue = null;
         private StateMachine() { super(); }
         private StateMachine(String name) {
              super(name);
              states = StateList.newInstance(this);
              changed = false;
         public static StateMachine newInstance(String name) {
              StateMachine sm = new StateMachine(name);
              sm.initialize();
              return sm;
    public class StateList extends AbstractIOCList<State> {
         private StateMachine sm;
         private StateList() { super("StateList"); sm = null; }
         private StateList(StateMachine sm) {
              this();
              this.sm = sm;
         public static StateList newInstance(StateMachine sm) {
              StateList list = new StateList(sm);
              list.initialize();
              return list;
    ...etc. etc.
    I do serialization calling ObjectOutputStream.writeObject on the root object and (obviously) deserialize using ObjectOutputStream.readObject.
    The process works, but it seems that the default constructors in particular AbstractIOCLeaf() is never called while deserializing. First hint to something amiss was the fact that I always had the transient field changeListeners remaining in its default null state.
    Further investigation involving debugging and breakpointing confirmed no default constructor is called in spite of the super(); calls.
    What am I doing wrong??
    Did I miss something about serialization (apparently so, but I cannot understand what!)?
    Side issue:
    I tried substituting ObjectOutputStream.writeObject with XMLEncoder.writeObject, but then I get the error: "Class sun.reflect.misc.Trampoline can not access a member of class com.softin.IOCbuilder.model.IOController with modifiers "private"".
    Aren't those classes supposed to be equivalent?
    Is there any (fast) way to desume the offending member?
    Excuse me for the length of the post and
    Thanks in Advance
    Mauro

    Oops, nevermind. Sorry.

  • Serialization

    I am having this problem with serialization
    When the first time i am writing an object using the objectoutputstring of string class to a file , nothing but some ascii characters are written. But after that whatever string i wnt to write using the objectoutputstream it is successfully written .What could be the problem !!

    This forum is for Cryptography related problems. Since your problem seems to be nothing to do with Cryptography and everything to do with Serialization you would probably do better to post this in the 'Serialization' forum.

  • Web Service - Serialization failed

    Hello everybody
    I have a problem of Serialization.
    I have developed a web service with SE80.
    I have executed  WSDL file of web service developed with XMLSpy.
    This is the log of error:
    <soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
         <soap-env:Body>
              <soap-env:Fault>
                   <faultcode>soap-env:Client</faultcode>
                   <faultstring xml:lang="en">Serialisation failed</faultstring>
                   <detail>
                        <n0:SimpleTransformationFault xmlns:n0="http://www.sap.com/transformation-templates">
                             <MainName>/1BCDWB/WSS0070126110220757577</MainName>
                             <ProgName>/1BCDWB/WSS0070126110220757577</ProgName>
                             <Line>8 </Line>
                             <Valid>X</Valid>
                             <SerialisationFault>
                                  <DescriptionText>An error occurred during serialization in the simple transformation program /1BCDWB/WSS0070126110220757577</DescriptionText>
                                  <DescriptionDetailText/>
                                  <AbapPosition/>
                                  <ClassName>CX_ST_REF_ACCESS</ClassName>
                             </SerialisationFault>
                             <Caller>
                                  <Class>CL_SRG_RFC_PROXY_CONTEXT</Class>
                                  <Method>IF_SXML_PART~DECODE</Method>
                                  <Positions>1 </Positions>
                             </Caller>
                        </n0:SimpleTransformationFault>
                   </detail>
              </soap-env:Fault>
         </soap-env:Body>
    </soap-env:Envelope>
    SOME HELPS ????
    Thanks,
            Antonio

    Hi,
    Which SP do you have on NW640? I see Note 830340 - SOAP request - Deserialisation failed. It's about Deserialisation, but the output is simular.
    It says: Summary
    Symptom
    The call of an ABAP Web service fails. The system returns a SOAP Fault and the faultstring field has the value, "Deserialisation failed".
    "Solution
    You can correct the problem by importing the relevant Support Package. You cannot implement the correction in a manual way since it also requires changes delivered in Support Package SAPKB64009"
    Eddy
    Pimp up the S(D)N site and earn points. Check this <a href="/people/eddy.declercq/blog/2007/02/01/pimp-up-the-jam log</a> for details. Deadline Feb 15th!

Maybe you are looking for

  • Exchange 2013 SP1 Readiness Checks: No Exchange 2007 server detected

    Hi there, We are planning to upgrade our current Exchange 2007 server with the new Exchange 2013 SP1. I have been following Exchange Server Deployment Assistant to assist me with this task. Only schema update (setup /PrepareSchema) had been done so f

  • Lookup expression is not working when I am using with in the rectangle box in SSRS

    I have two datasets with common member is ProgramID. I have followed the below steps, 1. Added one table  (2x2) and mapped this table to dataset1. After that I have removed top row.                                                That means I am maint

  • Check on partner function detail

    Hi , all In CRM order taking , to parter function tab  , click the button 'Detail' below , then you can get the partner detail information , how can i check those input fields ? for example , some must input , some can not be changed etc ? any badi o

  • HT201363 how to unblock my i pod

    Hey how can i un block my i pod

  • Audio Tracking Suddenly Off

    I'm experiencing a wierdness for the first time in iMovie. I am doing a final edit on a movie and noticing that my audio track has shifted slightly, enough to be noticeable. This was not happening a few weeks ago when I finished my last movie. I am m