1 Reply Latest reply on Jun 11, 2014 3:20 AM by Jagadeesh-Oracle

    Unexpected output from jre6 on Linux

    Jagadeesh-Oracle

      Here is the issue with jre6.0:

      We have test program that subtract between two numbers, taken by substringing last 2 digits from two string values.

      If we compile and run it with jre6.0 gives different result. Attaching the program here.

       

      1. TestJreIssue.java and TestSubstr3.java can can compile them and execute with the jre present in /NM511/jre/bin  (of NM511-eFix27(Linux) version).

      2. Execute it with /NM511/jre/bin/java TestJreIssue    or /NM511/jre/bin/java TestSubstr3

      3. You will see the out put as

      $ /apps/NM511/jre/bin/java TestJreIssue

      Started with the program..wait till it exists

      Not MultiThreaded *************centidiff value is: 85

      Not MultiThreaded *************end_centi value is: 87

      Not MultiThreaded *************ans_centi value is: 32

      Wrong value calculated for centidiff.. Expected is 53 and got 85 why ???

      Error at iteration no 17328

      Not MultiThreaded *************centidiff value is: 149

      Not MultiThreaded *************end_centi value is: 87

      Not MultiThreaded *************ans_centi value is: 34

      Wrong value calculated for centidiff.. Expected is 53 and got 149 why ???

      Error at iteration no 34019

       

      4. Whereas the code should always get 53 as the result.

       

      Why is this difference with jre6.0? but no issues with jre7.0 but customer can use only jre6.0?

       

      Thanks,

      Jagadeesh

        • 1. Re: Unexpected output from jre6 on Linux
          Jagadeesh-Oracle

          Here is the sampleTestjreIssue.java:

          ----------------------------

          public class TestJreIssue {

           

            //int ans_centi=0;

            //int end_centi=0;

            //int centidiff =0;

           

            public static void main(String [] args){

            TestJreIssue object  = new TestJreIssue();

           

            System.out.println ("Started with the program..wait till it exists");

            long start = System.currentTimeMillis();

            for (int i=0; i< 60000; i++) {

           

            object.run1(i);

            }

            long finish = System.currentTimeMillis();

           

            System.out.println("Test1 Took: " + (finish - start) + " msecs");

            }

           

           

          public void run1(int i){

            String disconTime ="2014060205345887";   // take last two digits 87

            String  ansTime   ="2014060205345834"; // take last two digits 34

           

           

           

            int end_centi = Integer.parseInt(disconTime.substring(disconTime.length()-2));

            int ans_centi = Integer.parseInt(ansTime.substring(ansTime.length()-2));

           

            //end_centi = Integer.parseInt(disconTime.substring(disconTime.length()-2));

            //ans_centi = Integer.parseInt(ansTime.substring(ansTime.length()-2));

            int centidiff =0;

            //int centidiff =0;

           

            //System.out.println(" end_centi: " + end_centi+" ans_centi: " + ans_centi+" centidiff: " + centidiff+" itr: " + i);

           

            if(end_centi < ans_centi) {

           

            centidiff = (end_centi + 100 ) - ans_centi;

           

            } else {

           

            centidiff = (end_centi-ans_centi);

           

            }

           

            if (! (53 == centidiff)) {

            System.out.println("Not MultiThreaded *************centidiff value is: " + centidiff);

            System.out.println("Not MultiThreaded *************end_centi value is: " + end_centi);

            System.out.println("Not MultiThreaded *************ans_centi value is: " + ans_centi);

            System.out.println("Wrong value calculated for centidiff.. Expected is 53 and got " + centidiff + " why ???" );

            System.out.println("Error at iteration no " +i );

            //System.exit(-1);

            }

            }

          }

           

          TestSubstr3.java

          ------------------------

          public void run1(){
          String disconTime ="2014060205345887";
          String  ansTime ="2014060205345834";
          // get the centi seconds difference manuall without any date function
          int end_centi = Integer.parseInt(disconTime.substring(disconTime.length()-2));
          int ans_centi = Integer.parseInt(ansTime.substring(ansTime.length()-2));
          //System.out.println("end and ans centis are : " + end_centi + ", " + ans_centi);
          //ONMLogger.ERROR.log(FQCN, "2. Debug for discon issue --->>>> RSN : " + rsn + " fileName :"  + fileId + " fileName :" + fileName + " disconDtTime :" + disconDtTime + "" );
          //ONMLogger.ERROR.log(FQCN, "3. Debug for discon issue --->>>> RSN : " + rsn + " fileName :"  + fileId + " fileName :" + fileName +"(Before) end and ans centis are : " + end_centi + ", " + ans_centi);
          int centidiff =0;
          if(end_centi < ans_centi) {
          centidiff = (end_centi + 100 ) - ans_centi;
          //ONMLogger.ERROR.log(FQCN, "3.1. Debug for discon issue --->>>> RSN : " + rsn + " fileName :"  + fileId + " fileName :" + fileName +" (In If loop) end and ans centis are : " + end_centi + ", " + ans_centi + " centidiff " + centidiff);
          } else {
          centidiff = end_centi-ans_centi;
          //ONMLogger.ERROR.log(FQCN, "3.2. Debug for discon issue --->>>> RSN : " + rsn + " fileName :"  + fileId + " fileName :" + fileName +" (In Else loop) end and ans centis are : " + end_centi + ", " + ans_centi + " centidiff " + centidiff);
          }
          if (! (53 == centidiff)) {
          System.out.println("Not MultiThreaded *************centidiff value is: " + centidiff);
          System.out.println("Not MultiThreaded *************end_centi value is: " + end_centi);
          System.out.println("Not MultiThreaded *************ans_centi value is: " + ans_centi);
          System.out.println("Wrong value calculated for centidiff.. Excpected is 53 and got " + centidiff + " why ???" );
          System.exit(-1);
          }
          }

          }