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

C2: Missing NegativeArraySizeException when creating StringBuilder with negative capacity

    XMLWordPrintable

Details

    • b18
    • generic
    • generic
    • Verified

    Backports

      Description

        ADDITIONAL SYSTEM INFORMATION :
        # Java version
        java version "16.0.2" 2021-07-20
        Java(TM) SE Runtime Environment (build 16.0.2+7-67)
        Java HotSpot(TM) 64-Bit Server VM (build 16.0.2+7-67, mixed mode, sharing)

        # Operating system details
        $ cat /etc/*release
        DISTRIB_ID=Ubuntu
        DISTRIB_RELEASE=20.04
        DISTRIB_CODENAME=focal
        DISTRIB_DESCRIPTION="Ubuntu 20.04.2 LTS"
        NAME="Ubuntu"
        VERSION="20.04.2 LTS (Focal Fossa)"
        ID=ubuntu
        ID_LIKE=debian
        PRETTY_NAME="Ubuntu 20.04.2 LTS"
        VERSION_ID="20.04"
        HOME_URL="https://www.ubuntu.com/"
        SUPPORT_URL="https://help.ubuntu.com/"
        BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
        PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
        VERSION_CODENAME=focal
        UBUNTU_CODENAME=focal

        $ uname -a
        Linux zzq-ThinkPad-T470 5.4.0-77-generic #86-Ubuntu SMP Thu Jun 17 02:35:03 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

        A DESCRIPTION OF THE PROBLEM :
        Different outputs of the attached program are observed between different compilation tiers. This bug affects Oracle 1.8.0_301, 11.0.12, 16.0.2 and early access build 17-ea+32-2679 and 18-ea+7-288.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        # Compile
        $ javac C.java

        # Default or compilation up to level 4
        $ java C

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        10000
        ACTUAL -
        # Non-deterministic
        5597

        ---------- BEGIN SOURCE ----------
        # C.java
        (Attached.)
        public class C {

            static String m() {
                StringBuilder sb = new StringBuilder(-1);
                return sb.toString();
            }

            public static void main(String[] args) {
                int sum = 0;
                for (int i = 0; i < 10_000; ++i) {
                    try {
                        m();
                    } catch (Throwable e) {
                        sum += 1;
                    }
                }
                System.out.println(sum); // should be 10_000
            }
        }
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        # Compilation up to level 1
        $ java -XX:TieredStopAtLevel=1 C
        # Output (correct)
        10000

        # Interpreter or compilation up to level 0
        $ java -Xint C
        # Output (correct)
        10000

        FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

                chagedorn Christian Hagedorn
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                13 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: