JDK-8235812 : Unicode linebreak with quantifier does not match valid input
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.regex
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2019-12-12
  • Updated: 2020-12-14
  • Resolved: 2020-02-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 15
15 b10Fixed
Related Reports
Relates :  
Relates :  
Description
The char class \R is defined to be \u000D\u000A|[\u000A\u000B\u000C\u000D\u0085\u2028\u2029].

Therefore, the regex \\R{2} must match the sequence \r\n (first \R matches \r, and the second \R matches \n).
In fact, it does not.

import java.util.regex.*;

public class RR {
    public static void main(String[] args) throws Throwable {
        Pattern p = Pattern.compile("\\R{2}");
        System.out.println(Boolean.toString(p.matcher("\r\r").matches()));
        System.out.println(Boolean.toString(p.matcher("\r\n").matches()));
        System.out.println(Boolean.toString(p.matcher("\n\r").matches()));
        System.out.println(Boolean.toString(p.matcher("\n\n").matches()));
        System.out.println(Boolean.toString(p.matcher("\r\n\r").matches()));
        System.out.println(Boolean.toString(p.matcher("\r\r\n").matches()));
        System.out.println(Boolean.toString(p.matcher("\r\n\n").matches()));
        System.out.println(Boolean.toString(p.matcher("\n\r\n").matches()));
        System.out.println(Boolean.toString(p.matcher("\r\n\r\n").matches()));
    }
}

prints the following (expected all 9 results be 'true'):

true
false
true
true
true
true
true
true
true
Comments
URL: https://hg.openjdk.java.net/jdk/jdk/rev/ae7a326448fa User: igerasim Date: 2020-02-11 00:11:07 +0000
11-02-2020