Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8274118

intern() results are not consistent

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      java version "1.8.0_102"
      Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      @Test
          public void test015(){
              String s3 = new String("4") + new String("9");
              s3 = s3.intern();
              String s4 = "49";
              System.out.println(s3 == s4); // 10,true
          }

          @Test
          public void test016(){
              String s3 = new String("3") + new String("9");
              s3 = s3.intern();
              String s4 = "39";
              System.out.println(s3 == s4); // 11,false
          }

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      @Test
          public void test015(){
              String s3 = new String("4") + new String("9");
              s3 = s3.intern();
              String s4 = "49";
              System.out.println(s3 == s4); // 10,true
          }

          @Test
          public void test016(){
              String s3 = new String("3") + new String("9");
              s3 = s3.intern();
              String s4 = "39";
              System.out.println(s3 == s4); // 11,false
          }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      all true
      ACTUAL -
      one false
      on true

      ---------- BEGIN SOURCE ----------
      @Test
          public void test015(){
              String s3 = new String("4") + new String("9");
              s3 = s3.intern();
              String s4 = "49";
              System.out.println(s3 == s4); // 10,true
          }

          @Test
          public void test016(){
              String s3 = new String("3") + new String("9");
              s3 = s3.intern();
              String s4 = "39";
              System.out.println(s3 == s4); // 11,false
          }
      ---------- END SOURCE ----------

      FREQUENCY : always


            tongwan Andrew Wang
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: