This discussion is archived
1 2 3 Previous Next 31 Replies Latest reply: Mar 21, 2012 4:59 PM by jschellSomeoneStoleMyAlias Go to original post RSS
  • 15. Re: double primitive or Double is being corrupted(chopping off numbers)
    796440 Guru
    Currently Being Moderated
    user10916752 wrote:
    The problem that I am having is that I don't know where to begin to look. We have 13 servers in a farm with 5 core applications running, a couple of thousand application options, thousands of users. Three different servers had the problem in the last month.
    In anticipation of it being a formatting issue, I'd start by doing research into whatever Formatters, DecimalFormats, Locales, etc. are used between where you call System.out.println(35.5) and where the sequence of characters actually gets sent down the stream, and in particular, any of them that are "system-wide" or otherwise shared by common output or formatting classes. For instance, any call to Locale.setDefault() would be a major red flag here. Then you can use grep or your IDE to search for calls that could modify which one is used or how it behaves. If you don't have source code for everything, you may have to consider attaching a debugger to one or more systems with a tracepoint set on these calls.

    Another thing you can do is create a heap dump when you detect that the problem is occurring, and examine it for things like System.out and other "global" objects not being what they should be.

    Meanwhile, I would start putting together an upgrade plan to get to the latest version of Java. I doubt that will fix anything, but it does take one variable out of the mix.

    Edited by: jverd on May 2, 2011 2:26 PM
  • 16. Re: double primitive or Double is being corrupted(chopping off numbers)
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    Just as a thought...

    CPUs these days have floating point processors.

    What happens when one of those becomes flaky (on its way to failure) in terms of formatted output?

    If something is replacing something it shouldn't you could add a Security Manager to prevent it.
  • 17. Re: double primitive or Double is being corrupted(chopping off numbers)
    859049 Newbie
    Currently Being Moderated
    Thanks again for all the help. Sounds like a good plan. I'm going to go this route. This makes sense. I'll post something if I find the problem.
  • 18. Re: double primitive or Double is being corrupted(chopping off numbers)
    796440 Guru
    Currently Being Moderated
    jschell wrote:
    Just as a thought...

    CPUs these days have floating point processors.

    What happens when one of those becomes flaky (on its way to failure) in terms of formatted output?
    He did say he observed the behavior on 3 servers, so a hardware problem seems unlikely. Unless those servers' CPUs happened to roll off the assembly line in the same batch and happened to have the same defect out the door.
  • 19. Re: double primitive or Double is being corrupted(chopping off numbers)
    859049 Newbie
    Currently Being Moderated
    Just an update... Sorry if this is not structured well.

    I downloaded the java source and did some analysis on System.out.println(double). I looked at the source starting with println(double).
    System.out.println(double) is coded in PrintStream.java. println(double) calls write(String.valueOf(double)). String.valueOf(double) calls Double.toString(double). Double.toString(double) returns "new FloatingDecimal(d).toJavaFormatString();" FloatingDecimal constructor calls Double.doubleToLongBits( double ); which calls doubleToLongBits which calls doubleToRawLongBits and is native to the JVM. FloatDecimal constructor does many other things to setup some private variables. toJavaFormatString makes use of the doubleToRawLongBits value and the other variables and creates a string that is then written out by PrintStream. That is the full circle. No formatters, locale used.
    I also followed float in the same fashion. The one difference from double was the call to the native JVM method floatToRawLongBits.

    At this point I can only deduce that the failure is either in FormattingDecimal or the JVM. As it appears that float works very much like double in FormattingDecimal, and float had no problems, but double did, then things still point to the JVM. Am I insane or what?
  • 20. Re: double primitive or Double is being corrupted(chopping off numbers)
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    jverd wrote:
    He did say he observed the behavior on 3 servers, so a hardware problem seems unlikely.
    Yeah I missed that.
  • 21. Re: double primitive or Double is being corrupted(chopping off numbers)
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    GBru wrote:
    At this point I can only deduce that the failure is either in FormattingDecimal or the JVM.
    It isn't in the VM nor the Java API - in general.

    But say you have an install, which pulls from a single source which includes a jre (VM and Java API) and there is some small corruption there. Then it is possible. But very unlikely. You could do a checksum comparison by starting with a original version of the VM (not one from your build system.) Do it with the build system and with an install.

    It could be a hardware failure if the 3 servers are EXACTLY the same. So same vendor, same part #, same # CPUs, same memory etc. And ordered at the same time. Thus if there was some flaky hardware then three consecutively produced boxes could have it. But really, really unlikely.

    It could be something pluging something in or changing something in the VM. That would explain it. And the intermittent nature is explained because it is unplugging it as well (or it only happens randomly for some other reason.) As I suggested adding a Security Manager would both allow you to track it and prevent it.
  • 22. Re: double primitive or Double is being corrupted(chopping off numbers)
    859049 Newbie
    Currently Being Moderated
    Thanks for your response. I'll take these things into consideration. This is a very disturbing problem. At least we now have something in place that will alert us as soon as it happens.
  • 23. Re: double primitive or Double is being corrupted(chopping off numbers)
    859049 Newbie
    Currently Being Moderated
    An update on this item....

    We continue to have this problem. This a critical problem. When the problem happens, client data is corrupted. We do have an alert in place to let us know as soon as it happens, but it continues to be a big problem.
    We are running java 1.6.0_07 and tomcat 5.5 and are moving toward upgrading to Java 7 and Tomcat 7. Maybe this will fix the problem.

    I have a floattest.jsp that has the following code:

    <%=new FloatingDecimal(3.25 ).toJavaFormatString()%>
    When the corruption occurs, this produces the result of 3.0. It should be 3.25.
    All doubles being processed when corruption happens are wrong at this point. Floats are ok.

    The last time that this happened, I got the source code for FloatingDecimal and embbeded it in my floattest.jsp.
    A call to the embbed source version produced the correct number 3.25. The call to the original loaded class FloatingDecimal produced 3.0.
    Both in the same jsp, producing different results.
  • 24. Re: double primitive or Double is being corrupted(chopping off numbers)
    EJP Guru
    Currently Being Moderated
    What's FloatingDecimal?
  • 25. Re: double primitive or Double is being corrupted(chopping off numbers)
    796440 Guru
    Currently Being Moderated
    EJP wrote:
    What's FloatingDecimal?
    sun.misc.FloatingDecimal
  • 26. Re: double primitive or Double is being corrupted(chopping off numbers)
    796440 Guru
    Currently Being Moderated
    GBru wrote:
    An update on this item....

    We continue to have this problem. This a critical problem. When the problem happens, client data is corrupted. We do have an alert in place to let us know as soon as it happens, but it continues to be a big problem.
    We are running java 1.6.0_07 and tomcat 5.5 and are moving toward upgrading to Java 7 and Tomcat 7. Maybe this will fix the problem.

    I have a floattest.jsp that has the following code:

    <%=new FloatingDecimal(3.25 ).toJavaFormatString()%>
    When the corruption occurs, this produces the result of 3.0. It should be 3.25.
    All doubles being processed when corruption happens are wrong at this point. Floats are ok.

    The last time that this happened, I got the source code for FloatingDecimal and embbeded it in my floattest.jsp.
    A call to the embbed source version produced the correct number 3.25. The call to the original loaded class FloatingDecimal produced 3.0.
    Both in the same jsp, producing different results.
    Is there perhaps another FloatingDecimal class floating around somewher? Not the one from sun.misc? Or maybe from an older version of Java that didn't get completely cleaned up? Or one that somebody wrote or modified himself? Maybe that is getting picked up on some classpath ahead of the real one in some cases?

    It's a stretch, I know, but if directly using FD produces the error running what should be the exact same code inline produces good results, then the FD class you're loading must be different, right?

    If you can't find the rogue FD class, and can't find any other source for the problem, maybe compile the known good (or apparently good) source code, in a sun.misc package, and put that class somewhere that you can be sure it will always be at the very head of all relevant classpaths.

    Of course, if there IS a rogue FD class, and if it's on some classpath that's getting prepended to existing ones further down the line, this won't help.

    So, I guess, when the error occurs, you could get the ClassLoader for the FD class, and print out its classname, the URLs its searching for classes, pretty much every field it has, even if you have to reflectively call setAccessible(true) on private fields.

    EDIT: Also, as much information as you can get about the "bad" FD class. And collect all that for a good FD ClassLoader and Class as well for comparison.

    I don't know, just stream of consciousness here...

    Edited by: jverd on Nov 16, 2011 4:11 PM
  • 27. Re: double primitive or Double is being corrupted(chopping off numbers)
    EJP Guru
    Currently Being Moderated
    sun.misc.FloatingDecimal
    If that's the case he shouldn't be using it at all.
  • 28. Re: double primitive or Double is being corrupted(chopping off numbers)
    796440 Guru
    Currently Being Moderated
    EJP wrote:
    sun.misc.FloatingDecimal
    If that's the case he shouldn't be using it at all.
    He's not using it (directly) in his real code. He saw that the normal double formatting was using it under the covers. Then he put a direct call to it in his code, and put a call to inline code copied from that class into his code as well. At first things seem to be fine, then, at some point, using that class the way normal double formatting does produced the rounded value, while executing the inline code continued to produce the correct value. (At least, that's how I interpreted his comments.) This leads me to believe a corrupt version of the class is getting loaded at some point.
  • 29. Re: double primitive or Double is being corrupted(chopping off numbers)
    924836 Newbie
    Currently Being Moderated
    Any update on this problem? Was this resolved with Java 7?

    The exact same problem happens with us as well and it happens very randomly. Once it starts happening, it happens continuously until we restart the service.

    We don't have tomcat though, just plain Java 6 J2SE application.

    Arun

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points