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

Pattern.compile(String, int) fails to throw IllegalArgumentException

XMLWordPrintable

    • b24
    • x86
    • windows_7
    • Verified

        FULL PRODUCT VERSION :
        java version "1.7.0_51"
        Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
        Java HotSpot(TM) Client VM (build 24.51-b03, mixed mode, sharing)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows [Version 6.1.7601] (Windows 7, 32-bit)

        A DESCRIPTION OF THE PROBLEM :
        According to documentation (some parts omitted for brevity)

        http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html#compile%28java.lang.String,%20int%29

        public static Pattern compile(String regex,
                      int flags)
        [...]

        Throws:
            IllegalArgumentException - If bit values other than those corresponding to the defined match flags are set in flags

        However, the class doesn't check the flag at all.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Just compile a Pattern with 0xFFFFFFFF (all bits set)

            Pattern.compile("d", 0xFFFFFFFF)

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        IllegalArgumentException, since not all 32 bits are used by the flags
        ACTUAL -
        No Exception thrown

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        /* Author: Hong Dai Thanh/nhahtdh */
        import java.util.regex.*;

        class BugCompileBadFlag {
            public static void main(String args[]) {
                try {
                    System.out.println(Pattern.compile("d", 0xFFFFFFFF));
                } catch (IllegalArgumentException e) {
                    System.out.println(e.getMessage());
                }
            }
        }
        ---------- END SOURCE ----------

          There are no Sub-Tasks for this issue.

              igerasim Ivan Gerasimov
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: