Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8271302: Regex Test Refresh #5092

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -26,23 +26,25 @@
* @bug 7071819 8221431 8239383
* @summary tests Unicode Extended Grapheme support
* @library /lib/testlibrary/java/lang
* @run main GraphemeTest
* @run testng GraphemeTest
*/

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.regex.Matcher;

import org.testng.annotations.Test;
import static org.testng.Assert.fail;

public class GraphemeTest {

public static void main(String[] args) throws Throwable {
@Test
public static void testGraphemeBreakProperty() throws Throwable {
testProps(UCDFiles.GRAPHEME_BREAK_PROPERTY);
}

@Test
public static void testEmojiData() throws Throwable {
testProps(UCDFiles.EMOJI_DATA);
}

@@ -78,7 +80,7 @@ private static void testProps(Path path) throws IOException {
System.out.printf("[%x] [%s][%d] -> [%s]%n",
cp, expected, Character.getType(cp), types[getType(cp)]);
else
throw new RuntimeException(String.format(
fail(String.format(
"cp=[%x], expeced:[%s] result:[%s]%n",
cp, expected, types[getType(cp)]));
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -26,17 +26,17 @@
* @bug 8223174
* @summary Pattern.compile() can throw confusing NegativeArraySizeException
* @requires os.maxMemory >= 5g
* @run main/othervm NegativeArraySize -Xms5G -Xmx5G
* @run testng/othervm -Xms5G -Xmx5G NegativeArraySize

This comment has been minimized.

@pavelrappo

pavelrappo Aug 20, 2021
Member

I note that the order of the arguments has changed. Will that work as expected? Had it worked as expected before?

This comment has been minimized.

@igraves

igraves Aug 20, 2021
Author Member

The new order is consistent with other tests. I had difficulty getting it to run in the original configuration. Perhaps jtreg is more sensitive on order with the testng runner.

*/

import org.testng.annotations.Test;
import static org.testng.Assert.assertThrows;

import java.util.regex.Pattern;

public class NegativeArraySize {
public static void main(String[] args) {
try {
Pattern.compile("\\Q" + "a".repeat(42 + Integer.MAX_VALUE / 3));
throw new AssertionError("expected to throw");
} catch (OutOfMemoryError expected) {
}
@Test
public static void testNegativeArraySize() {
assertThrows(OutOfMemoryError.class, () -> Pattern.compile("\\Q" + "a".repeat(42 + Integer.MAX_VALUE / 3)));

This comment has been minimized.

@pavelrappo

pavelrappo Aug 20, 2021
Member

One observation on this regex. Although the regex looks invalid because \\Q misses the pairing \\E, it can still be compiled (with a reasonable number of a's, of course). Moreover, the resulting pattern matches strings in a surprising way:

jshell> Pattern.compile("\\Qaaa").matcher("aaa").matches()
$1 ==> true

This comment has been minimized.

@pavelrappo

pavelrappo Aug 20, 2021
Member

Maybe that behavior is expected after all. From "Mastering Regular Expressions" by Jeffrey E.F. Friedl, 3rd Edition, p. 136:

Literal-text span: \Q...\E

First introduced with Perl, the special sequence \Q...\E turns off all regex meta-characters between them, except for \E itself. (If the \E is omitted, they are turned off until the end of the regex.)

}
}