Static fields ARE being serialized

Hi there,
I wrote a small test class that serializes an object, writes the serialized object to file, read the serialized object from the file and then deserialize the object. The object being serialized contains normal fields, a transient field, and a few 4 static fields with varying access modifiers. For some reason the static variables ARE being serialized. From what I've read this should not happen, and for very good reasons.
Here is the object being serialized:
package serialization;
import java.io.Serializable;
import java.util.Formatter;
public class MySerializableObject implements Serializable {
     private static final long serialVersionUID = 1L;
     private int a = 1;
     private int b = 2;
     private transient int c = 3;
     static public int d = 4;
     static protected int e = 5;
     static private int f = 6;
     static int g = 7;
     @Override
     public String toString() {
          Formatter formatter = new Formatter();
          formatter.format("a=%1$s b=%2$s c=%3$s d=%4$s e=%5$s f=%6$s g=%7$s", a,b,c,d,e,f,g);
          return formatter.toString();
     public void setNewD(int newVal) {
          d = newVal;
}And here is the code that does the serialization:
package serialization;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public class FileContentsObjectSerializer {
     File file;
     public FileContentsObjectSerializer(String name) {
          this.file = new File(name);
          if (this.file.exists()) {
               this.file.delete();
          try {
               this.file.createNewFile();
          } catch (IOException e) {
               e.printStackTrace();
     public void serialize(Object o) throws IOException {
          FileOutputStream fos = new FileOutputStream(this.file);
          ObjectOutputStream oos = new ObjectOutputStream(fos);
          oos.writeObject(o);
          oos.close();
          fos.close();
     public Object deserialize() throws IOException, ClassNotFoundException {
          FileInputStream fis = new FileInputStream(this.file);
          ObjectInputStream ois = new ObjectInputStream(fis);
          Object o = ois.readObject();
          fis.close();
          ois.close();
          return o;
     public static void main(String args[]) {
          MySerializableObject mso = new MySerializableObject();
          mso.setNewD(100);
          System.out.println("Object being serialized:"+mso.toString());
          FileContentsObjectSerializer ofs = new FileContentsObjectSerializer("c:/temptest.txt");
          try {
               ofs.serialize(mso);
               MySerializableObject result = (MySerializableObject) ofs.deserialize();
               System.out.println("Deserialized Object:    "+result.toString());
          } catch (Exception e) {
               e.printStackTrace();
}And here is the results I get:
Object being serialized:a=1 b=2 c=3 d=100 e=5 f=6 g=7
Deserialized Object:    a=1 b=2 c=0 d=100 e=5 f=6 g=7As you can see, both results are exactly the same, even though the setNewD value is not called on the deserialized object.
Any ideas?

You are misinterpreting the result. Try this main instead:
    public static void main(String args[]) {
        MySerializableObject mso = new MySerializableObject();
        mso.setNewD(100);
        System.out.println("Object being serialized:"+mso.toString());
        FileContentsObjectSerializer ofs = new FileContentsObjectSerializer("c:/temptest.txt");
        try {
            ofs.serialize(mso);
            mso.setNewD(-100); //a-oogah!
            MySerializableObject result = (MySerializableObject) ofs.deserialize();
            System.out.println("Deserialized Object:    "+result.toString());
        } catch (Exception e) {
            e.printStackTrace();
    }

Similar Messages

  • In oracle Open Script (OATS) OracleEBS/Forms project all the elements or fields are being identified as web objects.

    In oracle Open Script (OATS), we have created an OracleEBS/Forms project. But when we try to record the script all the elements or fields are being identified as web objects. Due to this we are unable to use the functions like getText. Hence, please help.
    Example: The below line when executed gives an error " Failed to connect to the Oracle Forms applet after 90 seconds. Verify that the applet launching page opens, and that the Forms Startup Timeout setting is high enough for this site."
    forms.textField("/web:window[@index='0' or @title='Person']/web:document[@index='7' or @name='tabPage']/web:input_text[@id='PER_ID' or @name='PER_ID' or @index='0']").getText();
    We have already set the event timeouts in OpenScript Preferences -> Playback -> OracleEBS/Forms Functional as
    Forms startup time out = 90Sec
    Forms Action timeout = 120Sec
    Forms Response Timeout = 120 Sec.
    OpenScript
    Version: 12.4.0.1 Build 139

    If it is a name resolution I would try either replacing the server name in the script with the IP address or making an entry in the local host file of the machine trying to play back the script
    If you try one or both of those approaches does the script play back?

  • All display's active buttons or fields are being marked consequently by a blue square

    All my iPad Air display's active buttons and fields are being permanently marked one after another by a blue square. This square appeared suddenly, no application was installed on the day when it happened. I've rebooted the  iPad and updated the software to the latest version, but it didn't help.
    I kindly ask for the suggestions on fixing this unusual iPad error. if needed, I could send a video on this problem.
    Kestutis

    I Thought you meant you could upload it here or upload it to YouTube and post the link here.
    IF you can't do that, can you post a screenshot here? Hold the power button down and then tap the home button to take a screen shot. You will hear the camera shutter sound, the screen will flash white and the screenshot will appear in the photos app. You can tap the camera icon in the editing bar in the text block that you type your response in and then select the option to use an existing photo.

  • Adobe Reader files missing information in static fields after being emailed?

    Hello, I have emailed the same person three seperate times with an attached PDF file that does have some fillable fields and some static fields. One time I email them the file, and the data in the static fields has been changed, but the fillable fields are the same, so I emailed it again and this time all the fields are completely blank, any ideas?

    Email transmissions can do all kinds of things, including attachments getting damaged or lost.  Far better and safer is to use a file sharing service like Acrobat.com, Dropbox, Google Drive, ..., then send the link by email.

  • Integration Models: what fields are actually being transferred.

    Where can i go to find out what fields are actually being transferred as part of an integration model?  Specifically speaking what fields are being transferred to APO and back to R/3 in regards to Planned Orders. 
    thanks in advance,
    Brian

    Hi,
    A faster way to know this is to see the APO Inbound User Exit Master Data fields for the User-Exit Function.  For the Product see the Product Inbound User Exit.
    For the Product Master apart from Basic Data (Desc, Weight, Volume, UOMs, Alt UOMs ... etc),  the Lead Times, Planning Time Fences, GR Processing Times, Procurement Type and Keys, Lotsizes, LotSize Keys/Methods, Safety Stocks/Times/Coverages, Total Replenishment Lead Time all come across to APO Master data. Most of these fields in R/3 are in the MRP1-4 views and Basic Views.
    The ALE Settings for CIF (Models) defines whether these Master Data changes come immediately to APO or not.
    I am assuming you know this Trnx in CIF setup. (I have to lookup if you do not).
    In the User-Exit Code can be written to block the R/3 from Updating APO Fields.
    Similar to Products, there is a User-Exit for every time of Master Data in APO. Best place to look for a complete list is here.  Another easier way to test is to Populate all the fields in R/3 and see which show up in APO.
    Hope this helps.
    Regards,
    Ambrish Mathur

  • How to check what fields are output from ABAP to smartform

    Hi All,
    I am working on a Zcopy of RLB_INVOICE smart form and need to check what fields are being output to the vendor_address window in the smartform.
    I have examined the NACE setup and found "Medium -> printoutput", "Program -> ZRLB_INVOICE", "Form Routine -> "ENTRY_INS", "Form -> ZRLB_INVOICE", "PDF/SmartForm -> ZRLB_INVOICE".
    Where would I find the code that shows the direct correlation between the driver program and a specific element of the smart form.
    All I need to check is that all elements of the venfore address are being sent to the form as I am hearing reports that we are missing house number on the printed output.
    Many thanks

    Hi Meenakshi,
    First you find out your driver program. Here in your case it is ZRLB_INVOICE. Then within that check where address of the vendor is found and is assigned to which import parameter of the smartform.
    Check your smartform also. Find which all fields are being printed in that. If vendor_address window is an address window, then there will be uniques identifier passed to that window from the driver program.
    Regards,
    Abijith

  • Assembly Insert brings static field error, but I have no fields

    Hallo,
    I have a signed test-dll with only 1 class:
    Public Class cTable
      Inherits DataTable
    End Class
    When Importing the Assembly to Database in SQLServer 2012,  Managementstudio shows the Message below.
    I have no static Fields to set as Readonly Properties.
    What must I do?
    Thanks - torsten
    Fehler bei CREATE ASSEMBLY, weil der TB_Test.cTable-Typ in der safe-Assembly 'TB_Test' das statische Feld '__ENCList' aufweist. Attribute von statischen Feldern in safe-Assemblys müssen in Visual C# als 'readonly', in Visual Basic als ReadOnly oder in Visual
    C++ und Intermediate Language als 'initonly' gekennzeichnet werden. (Microsoft SQL Server, Fehler: 6211)

    Hi Bob,
    yes, the cTable inherits from System.Data.DataTable.
    The error comes when trying to insert then dll as 'saved' and also as 'external access'.
    When inserting as 'unsaved' Comes then error below, although the assembly is signed and a login for this key exists.
    Are the some Options for the Compiler in vs2013, so no static fields are created?
    Thanks - torsten
    Fehler bei CREATE ASSEMBLY für die TB_Test-Assembly, weil die TB_Test-Assembly für PERMISSION_SET = UNSAFE nicht autorisiert ist. Die Assembly ist autorisiert, wenn eine der folgenden Bedingungen zutrifft: Der Datenbankbesitzer (DBO) hat die UNSAFE ASSEMBLY-Berechtigung,
    und für die Datenbank ist die TRUSTWORTHY-Datenbankeigenschaft aktiviert; oder die Assembly ist mit einem Zertifikat oder einem asymmetrischen Schlüssel signiert, das bzw. der einen entsprechenden Anmeldenamen mit der UNSAFE ASSEMBLY-Berechtigung aufweist
    . (Microsoft SQL Server, Fehler: 10327)

  • Signature field is being deleted when pdf is uploaded - what can I do?

    I was contacted by another administrator who was having trouble uploading the latest version of a pdf form online. Everything looks great in Adobe Acrobat X and Reader, but when we put the document on our website, the signature fields are being deleted, and the tab order changes.
    When users want to look at the document, they must download it, so it's not in the browser when this happens (I know this can make a difference). Signatures are allowed, and field forns are allowed on this pdf. Is there some other setting that could be messing things up?

    Does this happen when the Adobe plugin is used in the browser, or a
    different one? My guess is it's the internal PDF plugin of the browser used
    (Firefox, Chrome and Safari have one), which is probably causing this
    behaivour.
    On Wed, Nov 26, 2014 at 7:33 PM, eviedentially <[email protected]>

  • Hi I have adobe CC for teams, a team member is having problems opening indesign we are being asked for a serial number, ive checked on our admin account and he is one our our registered 'members'. I wasnt the person who set this up originally so I'm a bit

    Hi I have adobe CC for teams, a team member is having problems opening indesign we are being asked for a serial number, ive checked on our admin account and he is one our our registered 'members'. I wasn't the person who set this up originally so I'm a bit lost, i cant seem to find any serial numbers on the my account section and it seems we have no registered products? can you help?

    Hi There,
    We have checked the details of your team, all seat are assigned properly.
    Now there are few details that we would need in a Private Message so that I can assist you appropriately.
    Name of the user:
    Email of the user:
    Meanwhile, try the below mentioned links.
    Creative Cloud applications ask for serial number
    Sign in, activation, or connection errors | CS5.5 and later, Acrobat DC
    [Note: Details that we need is critical, make sure you send them in via Private Message only.]
    Thanks,
    Atul Saini

  • Finding out if any modifications are being made in the fields in an editable datagrid

    Hi,
    I populated my data grid with an array
    collection(initDG=event.result.categorydtls.category) where
    initDGObject is the array collection.I made the data grid as
    editable.Now , when the user click's on submit(below data grid),
    the request for modifying the corresponding details in database
    should go only if the user makes any modification ,or else an alert
    should be shown saying that "you havent made any modifications".For
    this purpose i assigned "event.result.categorydtls.category" to
    another array collection initDGObject and ,in the function which
    will be invoked after clicking on submit i compared both the
    objects initDG and initDGObject.But to my surprise,if any field in
    data grid is modified then both initDG and intiDGObject(here let me
    remind that i assigned initDG as the data provider for grid and
    initDGObject is a normal array collection object for which the
    details are assigned to for comparison purpose) are also
    modifying.So i am unable to check if any modifications are being
    made before forwarding request for database modification to back
    end.Please suggest me a solution for doing this task.Thanks in
    advance.

    lam not able to add a single object to the array
    collection.Regarding the usage of datagrid in my task,there will be
    a drop down on the top of datagrid with categories(like
    science,maths...)in it.Whenever a particular category is selected
    then the corresponding subcategories(in category science sub
    categories are physics,biology.....)details will be populated in
    the datagrid.Please suggest me a solution.

  • Static fields storage area

    Hi,
    local variables are stored on the stack which is private to each thread, all classes instaces are stored on the heap which is shared amongst all threads,
    so where are static class variables stored? they're not instances and they are shared amongst all threads....

    In older versions of the JVM the memory areas could be divided, Method Area and the heap. In the new implementations however there is no such segregation.vm spec, section 3.5.4 supports exactly what you said:
    Although the method area is logically part of the heap, simple implementations may choose not to either garbage collect or compact it.
    yet I can't find a clear explanation in there regarding static fields storage....
    I guess it doesn't really matter, since the destinction between the method area and the heap is not mandated by the spec...

  • Static fields in serialized Vector objects

    just a curious question:
    If I have a Vector filled with Objects of all the same type, and the Object contains a static field, and I then Serialize the Vector, will it still give better performance than if the field wasn't static? Thanks,
    Max

    nevermind - found out the hard way that static fields won't get Serialized

  • Recording which articles are being read

    I want to create a cloud tag of popular topics
    What i need to work out
    1. How to record which articles are being read
    2. How to display these in a tag cloud
    3. Then when a user clicks on a tag - all the articles which
    similar
    tag are displayed
    What i have done so far (how am i going?)
    Db called tags
    Tables
    tag, article title, article url, article description
    # each article has a few different tags
    e.g
    article for preventing std has the following tags
    std, sex, safe sex, HIV
    # the article itself doesnt exist in the database as i read
    this
    wasn't good for SEO. so the article itself exists on a static
    page.
    I have close to 100 medicla articles and add about 4 or 5 a
    month
    so i would love to get this working to save me time and
    effort.
    Many thanks
    Mark Holloway
    coordinator
    www.healthhokkaido.com

    Have been using this code from the pete frei tutorial - cloud
    tags -. It is working fine.
    In the case of my database, each article has 3 tags
    associated.
    So there are 3 fields as opposed to 1 from which to count the
    tags.
    How could I adjust the code to take accountfor this?
    Also I am a begineer so if you had the time to provide a
    short explanation that would also be great.
    <cfquery datasource="cart" name="tags">
    SELECT COUNT(tag) AS tagCount, tag
    FROM list
    GROUP BY tag
    </cfquery>
    <cfset tagValueArray =
    ListToArray(ValueList(tags.tagCount))>
    <cfset max = ArrayMax(tagValueArray)>
    <cfset min = ArrayMin(tagValueArray)>
    <cfset diff = max - min>
    <cfset distribution = diff / 3>
    <style type="text/css">
    <!--
    .smallestTag { font-size: xx-small; }
    .smallTag { font-size: small; }
    .mediumTag { font-size: medium; }
    .largeTag { font-size: large; }
    .largestTag { font-size: xx-large; }
    -->
    </style>
    <cfoutput query="tags">
    <cfif tags.tagCount EQ min>
    <cfset class="smallestTag">
    <cfelseif tags.tagCount EQ max>
    <cfset class="largestTag">
    <cfelseif tags.tagCount GT (min + (distribution*2))>
    <cfset class="largeTag">
    <cfelseif tags.tagCount GT (min + distribution)>
    <cfset class="mediumTag">
    <cfelse>
    <cfset class="smallTag">
    </cfif>
    <a href="/tag/#tags.tag#"
    class="#class#">#tags.tag#</a>
    </cfoutput>

  • Static fields

    Can anyone tell me how compiler compiles static or 'final static' fields? Are they holding memory for whole period time of process, or when they're dereferenced, memory will be reclaimed during the process?
    Thanks

    I am fraid last response misunderstood my question
    and comments. Say there are 5000 static integers in
    application. It is 5000 bytes. Then there are 5000
    static String fields and each has 40 characters (each
    one is two bytes). Total static String may have
    400000 bytes. Each time the class that contains these
    fields is referenced at run time they take up memory.So are you saying that if these fields are not static? It wouldnot take memory? Or are you suggesting that there would always be only one instance of each of these classes so you wouldnot take more space if these fields are not static?
    So when application runs forever, it will have a
    great chance all these static will be loaded into
    memory. So total is 405K bytes that is 'permanently'
    stay in memory. You can claim this still a small
    amount. But this is just an example and everythingFirst of all its totally insignificant as to how much memory is being taken. The reasons under consideration for declairng a variable static are totally different from what you are assuming but even if you think this way let me tell you this much making them member variables would take more memory since now these variables would be associated with their respective instances and not the class object. And donot tell me that each of these classes is going to have only on instance, so multiply the value with the no. of instances, if you could tell how many instances you would have.
    is relative, depending on runtime system. So this is
    my original questions: if I want to do something to
    save a little bit memory that is permanently occupied
    by these static stuffs. But I like to know how
    compiler and runtime work: is that true if class is
    dereferenced, static field memory will be also
    reclaimed? If that is true, I don't need worry (that
    means these static fields do not 'permanently' stay
    in memory. If not true, I will review these fields toThis question has been answered in my previous post.
    see which one could be defined as instance fields or
    even defined on stack. The trade off always on
    allocate memory on globe heap and keep reference to
    it, or create object as needed.
    From your comments, seems you think both static and
    instance fields can be reclaimed memory if they are
    dereferenced (only difference is static is one copy
    and instance has multiple - that's obviously and not
    question we need discuss)Again you are wrong over here. Read the replies posted again. Secondly I repeat members are not defined static or regular based on the constraints you have in mind and secondly, the way you are thinking that the memory model works is totally wrong. To cut the story short you would not save any memory but making these members regular (non static) On the other hand you might break things by stepping into unknown terrotory since you are not trying to comprehend why were they made static in the first place.

  • Write to static field from instance method

    instance method writes to a static field. This is tricky to get correct if multiple instances are being manipulated, and generally bad practice.
    public static loadingDialog StatusWndw = null;
    StatusWndw = new loadingDialog(this);
    iwant to acces this satic field out side the class.
    how to slove this problem

    Make the LoadingDialog a singleton class. Lookup the singleton pattern.

Maybe you are looking for

  • How do I convert a pdf file to photoshop?

    how do I convert a pdf file to photoshop?

  • BDC line items greater than 7

    Hi, I have a sales order BDC program using Upload function to upload the file. It was working fine till now, as we are receiving more orders, this program is not working if we have the line items more than 7 in same order. Can you please help me how

  • 3.6.16 Broke My Tabs!!!! I can't open any new tabs now

    This morning I got a automatic Firefox update to 3.6.16. Foolishly I let the thing update. Now, I can't open any new tabs!!!!!!!! I've tried all three methods. ctrl-t, file new tab, and of course the new tab button on the tab bar. nothing works. It j

  • Transaction Variant for BD87 ? possible

    Hi all, I have the requirement to get a user access to BD87 but only for specific message types and status. I created a selection screen variant with the correct values. Then I tried to create a transaction in SE80 for the report + selection screen v

  • Overriding Superclass's Instance Variables?

    Ideally, this is what I'd like to accomplish: public abstract class AbstractClass {     public static final int variable = 0;     public static int getVariable() {         return variable; public class RealClass {     public static final int variable