8280403: RegEx: String.split can fail with NPE in Pattern.CharPredicate::match

Reviewed-by: lancea, iris, naoto, rriggs
This commit is contained in:
Ian Graves 2022-01-24 22:21:22 +00:00
parent 52ddbe2dcd
commit e3076552ec
2 changed files with 13 additions and 2 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2022, 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
@ -2689,6 +2689,8 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) {
else
prev = right;
} else {
if (curr == null)
throw error("Bad intersection syntax");
prev = prev.and(curr);
}
} else {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2022, 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
@ -4547,4 +4547,13 @@ public class RegExTest {
Pattern.compile(pattern));
assertTrue(e.getMessage().contains("Unescaped trailing backslash"));
}
//This test is for 8280403
@Test
public static void badIntersectionSyntax() {
String pattern = "[˜\\H +F&&]";
var e = expectThrows(PatternSyntaxException.class, () ->
Pattern.compile(pattern));
assertTrue(e.getMessage().contains("Bad intersection syntax"));
}
}