Different behaviour reading static field Windows vs Linux

I have a class B that is a subclass of class A. Class A has a protected static field. In windows, reading this field from a static method of class B yields the desired results, meaning that the field has the value updated somewhere else. Running the same code in Linux, the field contains the value assigned to it at declaration time:
It goes like this:
package packageA;
public class A
protected static Collection items = new ArrayList();
public static void addItem(Object item)
items.add(item);
} // class A
package packageB;
public class B
extends A
public static void methodA()
System.out.println(A.modules.size());
System.out.println(B.modules.getSize());
System.out.println(modules.size());
} // class B
import packageA.A;
import packageB.B;
public static void void main(String[] args)
Object item;
item = new String("");
A.addItem(item);
B.method();
} // main(String[])
What is even more strange, is that if I run the above example in a new project, the results are as expected. But if I run this other project I am working on, the results are as if B.items is independent of A.items. Even if I implement a method A.getItems() and call it from B.method() to store the items in a variable local to B.method(), the result is an empty ArrayList.
My first attempt was to place the A and B classes in the same package, and since the results were as expected, I changed each class to its own package and the Main class to an independent package. The results do not change in this scenario.
Your help is appreciated.
The environment is:
Netbeans 5.5
JRE 1.6.0-b105
xubuntu (Linux 2.6.20-16-generic i686 GNU/Linux(
Juan Carlos

I have just noticed that the "odd" behaviour does not happen everywhere (but it does happen everytime).
I realized that there is another part of code that references the same static field and the value in that case is the correct one.
Also, while debugging under Netbeans (on the line of code that gives the unexpected value), the "tip" that is displayed when the cursor is placed over the name of the field, the value is correct.
So I decided to check the Call Stack and noticed some Hidden Source Calls. They are hidden because of a call to LoginContext.login() Furthermore, that call results in a call to AccessController.doPrivileged()
Could that be the problem? If so, how do I solve it. At this point I am lost here, I don't have an idea of where to go now.
Thanks.
JC

Similar Messages

  • Difference in read/write between Windows Vs Linux

    Hi,
    Can you please write, whether it is a bug or my ignorance. I thought, if a java program runs in Windows then it will run in other platform too, without editing any code. It proved me wrong. So is it a bug?
    Ref: Fedora linux version 5
    Kernel ver. 2.6.17
    jdk version - build 1.5.0_06-b05
    I was working on a web service. The server side program connects to an application using socket program and sends back data to client.
    While it was working very fine with Windows XP. When I moved the service to Linux (above said linux). The program stopped working. When I explored it, I found 3 things.
    1. I was using PrintWriter
    PrintWriter outputStream = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()), true);
    to write into the socket. It works fine in Windows but not in Linux. ie. it sends different bytes in linux. Thus fails. When I changed it to BufferedOutputStream it works fine.
    BufferedOutputStream outputStream = new BufferedOutputStream (socket.getOutputStream());
    2. I was using BufferedReader to read
    BufferedReader inputStream = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    data from socket. It reads. But byte varies from expectation. The same program works very well with windows.
    I used DataInputStream now. that works. but..
    DataInputStream inputStream = new DataInputStream(socket.getInputStream());
    3. While reading it was suppossed to read 2098 bytes, instead it reads 1448 bytes. It reads correctly in Windows, but not in the above said linux.
    Is it a bug or there is a difference in reading and writing from socket between Windows and Linux ( even though it is same JVM).
    Thanks
    Sasi.

    Thanks a lot for both of you.
    I believe, \r\n Vs \n could not be the reason.
    Because, I was sending binary data.Then you should not be using Writer at all!
    >
    With regard to "utf-8", I thought of that but I did
    not try to issue it in the function. Because, I was
    trying to send and receive raw binary data.Then you should not be using Writer at all!
    >
    Now, You may ask that why did you use PrintWriter.
    Because, the data had unsigned byte values. Makes no difference - you should not be using Writer at all!
    So I
    converted everything in to char array and send it.Will cause you problems at some point on some platform unless you use Base64 or HEX encoding.
    especially, whereever unsigned byte was required, I
    used (byte & Oxff). It worked very well with
    Windows. So I just go ahead doing other things.I use byte & 0xff for dealing with unsigned valued but your use sounds dangerous.
    >
    Here my question is, I assumed that if a program is
    written in java and complied on jvm x, then
    irrespective of the underlying OS, if the jvm is the
    same x, then the program should run without error. Is
    it wrong. If it is not wrong, then is it a jre bug?Your program will work if you have not used any implicit or explicit platform dependencies. For example, if in your program then you have hard codes a path as "C:\Program Files" then it will work on Windows (but then only if it has a C drive) but not on Unix.
    Any program has to deal with a number of platform specific features and Java protects you from them as much as possible BUT you must deal with things like Locale, EOL and default character encoding.
    No! Of course it is not a jre bug. You have coded to a specific platform and are then are suprised when it fails on other platforms.
    >
    Did you see my third point of my original problem
    statement. How to solve that.Since I don't have a view of your code I can't make an informed comment. I think I can guess what the problem is but I won't speculate.

  • Different behaviour on windows and linux

    On a text field , I have attached a number converter, just to make sure that user enters the number else gets an error message.
    Things looks fine but it behaves differently on windows and linux os.
    When I am running this application on windows if user enters
    123456.46, it is stored as it is i.e 123456.46 in MySQL db.
    However, if run this on linux and if user enters 123456.46 then it is stored in MySQL db as 123456.460000000006402842700481414794921875
    I am not sure where the problem is. Can somebody guide me about it.
    Thanks.

    Not sure why the behaviour is different, but coded to remove the extra fractions.

  • Static fields on different machines

    Hi:
    Let us say I have a class
    public class Client(){private int static someField;
    I know if you are running Client.java on a single machine, obviously you will only get ONE incarnation of someField because it is static.
    Now, let us say I run the Client.java on different machines, then there will be one someField genearted per each JVM , is that right??
    can someone confirm??
    I did a serach on Static field on the Forum, but nobody really touched on running it on different machines, so I thought I ask...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

    Yes, that's right.

  • Static field for apps running on different machines

    Hi:
    Let us say I have a class
    public class Client(){
    private int static someField;I know if you are running Client.java on a single machine, obviously you will only get ONE incarnation of someField because it is static.
    Now, let us say I run the Client.java on different machines, then there will be one someField genearted per each JVM , is that right??
    can someone confirm??
    I did a serach on Static field on the Forum, but nobody really touched on running it on different machines, so I thought I ask...

    There will be one instance of the static variable per JVM regardless of whether the JVMs are running on the same machine or different machines.

  • 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.

  • Transportable tablespace Windows to Linux different character sets

    Hi,
    Is it absolutely necessary to have the same character set when doing a cross platform transport tablespace from Windows to Linux? We are trying to do it on Oracle10gR2 from Windows to Linux.
    Thank you.

    Hi, yes is necessary that your databases have the same chracter set, please review the limitations into the Note:291024.1.
    Luck.
    Have a good day.
    Regards.

  • Java program runs differently on Windows and Linux

    Hi!
    I would like to run a java application (which is written and run on windows platform) on linux platform. I don't know wether it is possible or not, but I tired on the following way:
    I have made a small java application. It worked correctly on windows (I developed it on windows). I copied first only the class file (Start.class) to the linux machine (which has exactly the same JDK as windows machine). When I type the command:
    java Startit gives me the folloving error:
    Exception in thread "main" java.lang.ClassFormatError: Start (unrecognized class file version)
       at java.lang.VMClassLoader.defineClass(libgcj.so.7rh)
       at java.lang.ClassLoader.defineClass(libgcj.so.7rh)
       at java.security.SecureClassLoader.defineClass(libgcj.so.7rh)
       at java.net.URLClassLoader.findClass(libgcj.so.7rh)
       at gnu.gcj.runtime.SystemClassLoader.findClass(libgcj.so.7rh)
       at java.lang.ClassLoader.loadClass(libgcj.so.7rh)
       at java.lang.ClassLoader.loadClass(libgcj.so.7rh)
       at gnu.java.lang.MainThread.run(libgcj.so.7rh)After that I was trying to compile the source file on linux with the command:
    javac Start.javabut the compiler gave me an error in the source file.
    Is there any way to run the formerly written java application (on windows) on linux machine?
    Thanks

    When I type the command java-version I get the following:
    java version "1.4.2"
    gij (GNU libgcj) version 4.1.2 20080704 (Red Hat 4.1.2-46)
    Copyright (C) 2006 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.The JDK on linux and windows is the latest (I was download it today).
    How can I upgrade the jdk/jre on linux?
    Here is the compiler error:
    [root@Linux-oracle app]# javac DataMining.java
    1. ERROR in DataMining.java (at line 77)
            ArrayList<String> temp = new ArrayList<String>();
            ^^^^^^^^^
    The type ArrayList is not generic; it cannot be parameterized with arguments <String>
    2. ERROR in DataMining.java (at line 77)
            ArrayList<String> temp = new ArrayList<String>();
                      ^^^^^^
    Syntax error, parameterized types are only available if source level is 5.0
    3. ERROR in DataMining.java (at line 77)
            ArrayList<String> temp = new ArrayList<String>();
                                         ^^^^^^^^^
    The type ArrayList is not generic; it cannot be parameterized with arguments <String>
    4. ERROR in DataMining.java (at line 77)
            ArrayList<String> temp = new ArrayList<String>();
                                                   ^^^^^^
    Syntax error, parameterized types are only available if source level is 5.0
    5. WARNING in DataMining.java (at line 240)
            String youtube[][] = new String[20][5];
                   ^^^^^^^
    The local variable youtube is never read
    6. WARNING in DataMining.java (at line 267)
            int e;
                ^
    The local variable e is never read
    7. ERROR in DataMining.java (at line 329)
            for(int i=1;i<Video+1;i++)
                          ^^^^^^^
    The operator + is undefined for the argument type(s) Integer, int
    7 problems (5 errors, 2 warnings)

  • How to schedule multiple reports with different local to change static field language ?

    Hi all,
    we have requirement that we will place multiple schedule request on same server ,This schedule request will be different local setting with parameter value like: en-GB,en-US,Chinese...etc .We used translation Manager for this and it takes this parameter and change report language for static fields.
    problem is that ,on server it is not working properly,we tested for one report .if we pass prompt value to change local setting in report the we need to log off and login again in CMC to reflect new local or on BI Launchpad we need to refresh page then it shows new language.
    How we can do this with multiple scheduled report which will have different local value like en-GB,en-US,Chinese,German....?These schedule request are getting placed in server by one user .
    Please help us with sample code.
    Thanks
    Madan

    Hi,
    The only approach I can think of is to create a template report which uses variables
    For each column you would need to variable
    v_columnAName and v_columnAValue
    v_columnAName would have a if statement in it
    =if([client]="clientA" or [client]="clientC";NameOf([firstName]);if([client]="clientB";NameOf([SSN]);NameOf([lastName]));
    v_columnA would have a if statement in it
    =if([client]="clientA" or [client]="clientC";[firstName];if([client]="clientB";[SSN],[lastName]));
    This would only work when you had a small set of clients.
    This might be more managable if it was done in the universe
    Regards
    Alan

  • What is different in deployment settings for 1033 in windows vs Linux

    Hi,
    I could not find correct source which could explain the variation in deployment settings while deploying my appliaction in windows and Linux.
    here is the scenario (10133)
    windows:
    When I deploy my ear with class loading path ( 3rd step in deployment @Configure Application Libraries)as default one i.e i dont specifiy any , the deployment is sucessful
    where as in Linux:
    I have to specify the class loading path to ear exploded directory in order get the application working. If i dont specify the path, the application wont start up , complains that some of the classes are not in class path.
    Please, can you expalin the cause or point me to location which explains this ?
    Thanks

    Please post some more information -- I can't offer much based on this. How is your application packaged -- you should not need to do what you are doing on Linux to pick up classes contained within the application itself, provided they are packaged and exposed using the standard J2EE/J2SE mechanisms.
    -steve-

  • Is read-only access to a static field correct without volatile/locking?

    Hello,
    I wonder wether the following code is safe:
    static UnicomServerCentral instance;
         public static void setInstance(UnicomServerCentral central)
              synchronized (UnicomServerCentral.class)
                   instance = central;
         public static UnicomServerCentral getInstance()
              UnicomServerCentral central = thisinstance;
              if (central == null)
                   synchronized (UnicomServerCentral.class)
                        central = this.instance;
              return central;
         }The static field instance is already guaranteed to be set. Is this safe?
    Thank you in advance, lg Clemens

    It might be safe in a particular context if there is
    additional synchronization involving the construction
    of the the "central" object and the execution of any
    threads that might call getInstance.Well if getInstance() returns null I simply spin as long as I get a non-null value back - so the only circumstance I could get here null is initialization.
    Since this example is a perfect does-not-work-dcl example I'll search the net for exmplanations.
    Thanks a lot, lg Clemens

  • Static field changes for both instances

    Whenever I construct a new object with a static field or use a set method on any of the instances of that object, the static field will change to the last modification made. In the case of my program, whenever the static String color field is changed to the last modification made. This only happens with the static fields, the other fields work just fine.
    Why does this problem occur?

    Sorry, I can't understand the question. If you have lots of different objects, all of the same class, they all share one copy of the static field, so if you invoke a method that changes the static field on one instance, all the other instances will see that change.
    if you don't want this behaviour, don't make the field static; then each instance will have its own copy of the field.

  • *** happened to iCal's STATIC info window... BRING IT BACK!!

    In iCal, the user interface is now completely useless. The static info window is now gone completely in favor of a dynamic info window which only comes up when typing command-i or double clicking on an event. The problem is that bringing up an info window for one event will always block events that come after it (to the right of it) and so you have to click somewhere off of the info window to close it and then click again on the next event to view the next event. What crap! In a given day or week or month, you cannot simply single click around to immediately see info of each event. Now it requires several more clicks for viewing each successive event (clicking off of the current even, then double clicking the next event of interest). Additionally, the size of the info window is always changing making your eyes always moving as you click around on different events and have to read an comprehend where the start/stop of each event is or then realize you have to scroll.
    How can we bring back the static view get info window!?!?!?!?!?!?!?!?!?!?!?! This is maddening!

    You can make suggestions to Apple regarding Mac OS X by submitting feedback here:
    http://www.apple.com/feedback/macosx.html

  • How can I share a static field between 2 class loaders?

    Hi,
    I've been googling for 2 days and it now seems I'm not understanding something because nobody seems to have my problem. Please, somebody tell me if I'm crazy.
    The system's architecture:
    I've got a web application running in a SunOne server. The app uses Struts for the MVC part and Spring to deal with business services and DAOs.
    Beside the web app, beyond the application context, but in the same physical server, there are some processes, kind of batch processes that update tables and that kind of stuff, that run once a day. Theese processes are plain Java classes, with a main method, that are executed from ".sh" scripts with the "java" command.
    What do I need to do?
    "Simple". I need one of those Java processes to use one of the web app's service. This service has some DAOs injected by Spring. And the service itself is a bean defined in the Spring configuration file.
    The solution is made-up of 2 parts:
    1. I created a class, in the web app, with a static method that returns any bean defined in the Spring configuration file, or in other words, any bean in the application context. In my case, this method returns the service I need.
    public class SpringApplicationContext implements ApplicationContextAware {
         private static ApplicationContext appContext;
         public void setApplicationContext(ApplicationContext context) throws BeansException {
              appContext = context;
         public static Object getBean(String nombreBean) {
              return appContext.getBean(nombreBean);
    }The ApplicationContext is injected to the class by Spring through the setApplicationContext method. This is set in the Spring configuration file.
    Well, this works fine if I call the getBean method from any class in the web app. But that's not what I need. I need to get a bean from outside the web app. From the "Java batch process".
    2. Why doesn't it work from outside the web app? Because when I call getBean from the process outside the web app, a different class loader is executed to load the SpringApplicationContext class. Thus, the static field appContext is null. Am I right?
    So, the question I need you to please answer me, the question I didn't find in Google:
    How can I share the static field between the 2 class loaders?
    If I can't, how can I load the SpringApplicationContext class, from the "Java batch process", with the same class loader my web app was started?
    Or, do I need to load the SpringApplicationContext class again? Can't I use, from the process, the class already loaded by my web app?
    I' sorry about my so extensive post...
    Thank you very much!

    zibilico wrote:
    But maybe, if the web service stuff gets to complicated or it doesn't fulfill my needs, I'll set up a separate Spring context, that gets loaded everytime I run the "Java batch process". It'll have it's own Spring configuration files (these will be a fragment of the web app's config files), where I'll define only the beans I need to use, say the service and the 2 DAOs, and also the DB connection. Additionally, I'll set the classpath to use the beans classes of the web app. Thus, if the service and DAOs were modified in the app server, the process would load the modified classes in the following execution.You'll almost certainly have to do that even if you do use RMI, Web services etc. to connect.
    What I suggest is that you split your web project into two source trees, the stuff that relates strictly to the web front end and the code which will be shared with the batch. The latter can then be treated as a library used by both the batch and web projects. That can include splitting Spring configuration files into common and specific, the common beans file can be retrieved from the classpath with an include. I regularly split web projects this way anyway, it helps impose decoupling between View/Controller and Model layers.
    On the other hand, you might consider running these batch processes inside the web server on background threads.

  • Adobe Reader 9.5.1 on Linux crashes every second time I try to print

    I can print perfectly.
    But if Adobe Reader stays open, and I try to print the same document a second time, or I try to print another document: In the moment I click on the Ok button in the print dialog, Adobe Reader crashes (window disappears) and nothing is printed.
    I have Adobe Reader 9.5.1 and cups 1.4.8.
    (Because I have cups 1.4.8 I don't think my problem is related to http://forums.adobe.com/thread/691846).

    I have the exact same problem with Adobe Reader 9.5.1 on Linux, gentoo build from sources of course, and the second time I try to print, or try to open a file or save, it means the second time you try to open a dialog that has something to do with system, it crashes...
    It can be reproducible on other distributions.
    :s
    I will not patch anything, but alternatives does not work as expected, also embedded into firefox has the same behaviour, and when it crashes you can not open any other pdf until you restart firefox and plugin reloads again...

Maybe you are looking for