1 /* |
1 /* |
2 * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
33 * 6350801 6676425 6878475 6919132 6931676 6948903 6990617 7014645 7039066 |
33 * 6350801 6676425 6878475 6919132 6931676 6948903 6990617 7014645 7039066 |
34 * 7067045 7014640 7189363 8007395 8013252 8013254 8012646 8023647 6559590 |
34 * 7067045 7014640 7189363 8007395 8013252 8013254 8012646 8023647 6559590 |
35 * 8027645 8035076 8039124 8035975 8074678 6854417 8143854 8147531 7071819 |
35 * 8027645 8035076 8039124 8035975 8074678 6854417 8143854 8147531 7071819 |
36 * 8151481 4867170 7080302 6728861 6995635 6736245 4916384 6328855 6192895 |
36 * 8151481 4867170 7080302 6728861 6995635 6736245 4916384 6328855 6192895 |
37 * 6345469 6988218 6693451 7006761 8140212 8143282 8158482 8176029 8184706 |
37 * 6345469 6988218 6693451 7006761 8140212 8143282 8158482 8176029 8184706 |
38 * 8194667 8197462 8184692 8221431 |
38 * 8194667 8197462 8184692 8221431 8224789 |
39 * |
39 * |
40 * @library /test/lib |
40 * @library /test/lib |
41 * @library /lib/testlibrary/java/lang |
41 * @library /lib/testlibrary/java/lang |
42 * @build jdk.test.lib.RandomFactory |
42 * @build jdk.test.lib.RandomFactory |
43 * @run main RegExTest |
43 * @run main RegExTest |
44 * @key randomness |
44 * @key randomness |
45 */ |
45 */ |
46 |
46 |
47 import java.util.function.Function; |
47 import java.io.BufferedReader; |
48 import java.util.regex.*; |
48 import java.io.ByteArrayInputStream; |
|
49 import java.io.ByteArrayOutputStream; |
|
50 import java.io.File; |
|
51 import java.io.FileInputStream; |
|
52 import java.io.InputStreamReader; |
|
53 import java.io.ObjectInputStream; |
|
54 import java.io.ObjectOutputStream; |
|
55 import java.math.BigInteger; |
|
56 import java.nio.CharBuffer; |
|
57 import java.nio.file.Files; |
|
58 import java.util.ArrayList; |
|
59 import java.util.Arrays; |
|
60 import java.util.List; |
49 import java.util.Random; |
61 import java.util.Random; |
50 import java.util.Scanner; |
62 import java.util.Scanner; |
51 import java.io.*; |
63 import java.util.function.Function; |
52 import java.nio.file.*; |
|
53 import java.util.*; |
|
54 import java.nio.CharBuffer; |
|
55 import java.util.function.Predicate; |
64 import java.util.function.Predicate; |
|
65 import java.util.regex.Matcher; |
|
66 import java.util.regex.MatchResult; |
|
67 import java.util.regex.Pattern; |
|
68 import java.util.regex.PatternSyntaxException; |
56 import jdk.test.lib.RandomFactory; |
69 import jdk.test.lib.RandomFactory; |
57 |
70 |
58 /** |
71 /** |
59 * This is a test class created to check the operation of |
72 * This is a test class created to check the operation of |
60 * the Pattern and Matcher classes. |
73 * the Pattern and Matcher classes. |
4930 } |
4944 } |
4931 } |
4945 } |
4932 } |
4946 } |
4933 report("Invalid capturing group names"); |
4947 report("Invalid capturing group names"); |
4934 } |
4948 } |
|
4949 |
|
4950 private static void illegalRepetitionRange() { |
|
4951 // huge integers > (2^31 - 1) |
|
4952 String n = BigInteger.valueOf(1L << 32) |
|
4953 .toString(); |
|
4954 String m = BigInteger.valueOf(1L << 31) |
|
4955 .add(new BigInteger(80, generator)) |
|
4956 .toString(); |
|
4957 for (String rep : List.of("", "x", ".", ",", "-1", "2,1", |
|
4958 n, n + ",", "0," + n, n + "," + m, m, m + ",", "0," + m)) { |
|
4959 String pat = ".{" + rep + "}"; |
|
4960 try { |
|
4961 Pattern.compile(pat); |
|
4962 failCount++; |
|
4963 System.out.println("Expected to fail. Pattern: " + pat); |
|
4964 } catch (PatternSyntaxException e) { |
|
4965 if (!e.getMessage().startsWith("Illegal repetition")) { |
|
4966 failCount++; |
|
4967 System.out.println("Unexpected error message: " + e.getMessage()); |
|
4968 } |
|
4969 } catch (Throwable t) { |
|
4970 failCount++; |
|
4971 System.out.println("Unexpected exception: " + t); |
|
4972 } |
|
4973 } |
|
4974 report("illegalRepetitionRange"); |
|
4975 } |
4935 } |
4976 } |