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

Scanner.nextInt(int) (and similar methods) throws PatternSyntaxException

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b143
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description

      FULL PRODUCT VERSION :
      sun-jdk-8u51

      ADDITIONAL OS VERSION INFORMATION :
      Linux checker 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt25-2+deb8u3 (2016-07-02) x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      If you call Scanner.nextInt(int) with a parameter < 2, you get a PatternSyntaxException, which is not a documented output.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      http://ideone.com/iuW4K0

      new Scanner("").nextInt(0);

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Some sort of exception saying "radix must be >= 2".
      ACTUAL -
      Exception in thread "main" java.util.regex.PatternSyntaxException: Unclosed character class near index 525
      (([-+]?(((((?i)[]|\p{javaDigit})++)|([\p{javaDigit}&&[^0]]((?i)[]|\p{javaDigit})?((?i)[]|\p{javaDigit})?(\,((?i)[]|\p{javaDigit})((?i)[]|\p{javaDigit})((?i)[]|\p{javaDigit}))+)))))|(((((?i)[]|\p{javaDigit})++)|([\p{javaDigit}&&[^0]]((?i)[]|\p{javaDigit})?((?i)[]|\p{javaDigit})?(\,((?i)[]|\p{javaDigit})((?i)[]|\p{javaDigit})((?i)[]|\p{javaDigit}))+)))|(\Q-\E((((?i)[]|\p{javaDigit})++)|([\p{javaDigit}&&[^0]]((?i)[]|\p{javaDigit})?((?i)[]|\p{javaDigit})?(\,((?i)[]|\p{javaDigit})((?i)[]|\p{javaDigit})((?i)[]|\p{javaDigit}))+)))
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ^
      at java.util.regex.Pattern.error(Pattern.java:1955)
      at java.util.regex.Pattern.clazz(Pattern.java:2548)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.sequence(Pattern.java:2063)
      at java.util.regex.Pattern.expr(Pattern.java:1996)
      at java.util.regex.Pattern.group0(Pattern.java:2905)
      at java.util.regex.Pattern.sequence(Pattern.java:2051)
      at java.util.regex.Pattern.expr(Pattern.java:1996)
      at java.util.regex.Pattern.group0(Pattern.java:2905)
      at java.util.regex.Pattern.sequence(Pattern.java:2051)
      at java.util.regex.Pattern.expr(Pattern.java:1996)
      at java.util.regex.Pattern.group0(Pattern.java:2905)
      at java.util.regex.Pattern.sequence(Pattern.java:2051)
      at java.util.regex.Pattern.expr(Pattern.java:1996)
      at java.util.regex.Pattern.group0(Pattern.java:2905)
      at java.util.regex.Pattern.sequence(Pattern.java:2051)
      at java.util.regex.Pattern.expr(Pattern.java:1996)
      at java.util.regex.Pattern.group0(Pattern.java:2905)
      at java.util.regex.Pattern.sequence(Pattern.java:2051)
      at java.util.regex.Pattern.expr(Pattern.java:1996)
      at java.util.regex.Pattern.group0(Pattern.java:2905)
      at java.util.regex.Pattern.sequence(Pattern.java:2051)
      at java.util.regex.Pattern.expr(Pattern.java:1996)
      at java.util.regex.Pattern.compile(Pattern.java:1696)
      at java.util.regex.Pattern.<init>(Pattern.java:1351)
      at java.util.regex.Pattern.compile(Pattern.java:1028)
      at java.util.Scanner$1.create(Scanner.java:367)
      at java.util.Scanner$1.create(Scanner.java:365)
      at sun.misc.LRUCache.forName(LRUCache.java:72)
      at java.util.Scanner.integerPattern(Scanner.java:443)
      at java.util.Scanner.nextInt(Scanner.java:2117)
      at Ideone.main(Main.java:12)

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.util.regex.PatternSyntaxException: Unclosed character class near index 525
      (([-+]?(((((?i)[]|\p{javaDigit})++)|([\p{javaDigit}&&[^0]]((?i)[]|\p{javaDigit})?((?i)[]|\p{javaDigit})?(\,((?i)[]|\p{javaDigit})((?i)[]|\p{javaDigit})((?i)[]|\p{javaDigit}))+)))))|(((((?i)[]|\p{javaDigit})++)|([\p{javaDigit}&&[^0]]((?i)[]|\p{javaDigit})?((?i)[]|\p{javaDigit})?(\,((?i)[]|\p{javaDigit})((?i)[]|\p{javaDigit})((?i)[]|\p{javaDigit}))+)))|(\Q-\E((((?i)[]|\p{javaDigit})++)|([\p{javaDigit}&&[^0]]((?i)[]|\p{javaDigit})?((?i)[]|\p{javaDigit})?(\,((?i)[]|\p{javaDigit})((?i)[]|\p{javaDigit})((?i)[]|\p{javaDigit}))+)))
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ^
      at java.util.regex.Pattern.error(Pattern.java:1955)
      at java.util.regex.Pattern.clazz(Pattern.java:2548)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.clazz(Pattern.java:2504)
      at java.util.regex.Pattern.sequence(Pattern.java:2063)
      at java.util.regex.Pattern.expr(Pattern.java:1996)
      at java.util.regex.Pattern.group0(Pattern.java:2905)
      at java.util.regex.Pattern.sequence(Pattern.java:2051)
      at java.util.regex.Pattern.expr(Pattern.java:1996)
      at java.util.regex.Pattern.group0(Pattern.java:2905)
      at java.util.regex.Pattern.sequence(Pattern.java:2051)
      at java.util.regex.Pattern.expr(Pattern.java:1996)
      at java.util.regex.Pattern.group0(Pattern.java:2905)
      at java.util.regex.Pattern.sequence(Pattern.java:2051)
      at java.util.regex.Pattern.expr(Pattern.java:1996)
      at java.util.regex.Pattern.group0(Pattern.java:2905)
      at java.util.regex.Pattern.sequence(Pattern.java:2051)
      at java.util.regex.Pattern.expr(Pattern.java:1996)
      at java.util.regex.Pattern.group0(Pattern.java:2905)
      at java.util.regex.Pattern.sequence(Pattern.java:2051)
      at java.util.regex.Pattern.expr(Pattern.java:1996)
      at java.util.regex.Pattern.group0(Pattern.java:2905)
      at java.util.regex.Pattern.sequence(Pattern.java:2051)
      at java.util.regex.Pattern.expr(Pattern.java:1996)
      at java.util.regex.Pattern.compile(Pattern.java:1696)
      at java.util.regex.Pattern.<init>(Pattern.java:1351)
      at java.util.regex.Pattern.compile(Pattern.java:1028)
      at java.util.Scanner$1.create(Scanner.java:367)
      at java.util.Scanner$1.create(Scanner.java:365)
      at sun.misc.LRUCache.forName(LRUCache.java:72)
      at java.util.Scanner.integerPattern(Scanner.java:443)
      at java.util.Scanner.nextInt(Scanner.java:2117)
      at Ideone.main(Main.java:12)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /* package whatever; // don't place package name! */

      import java.util.*;
      import java.lang.*;
      import java.io.*;

      /* Name of the class has to be "Main" only if the class is public. */
      class Ideone
      {
      public static void main (String[] args) throws java.lang.Exception
      {
      new Scanner("").nextInt(0);
      }
      }
      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            Assignee:
            sherman Xueming Shen
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: