This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit fd8e26e8d4a0dc212988057326c1427b88abe911 Author: Mark Thomas <ma...@apache.org> AuthorDate: Tue May 17 11:11:38 2022 +0100 Improve handling of errors associated with --enable-preview --- .../el/TestImportHandlerStandardPackages.java | 27 +++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/test/jakarta/el/TestImportHandlerStandardPackages.java b/test/jakarta/el/TestImportHandlerStandardPackages.java index 0d0c40c096..8d7def7005 100644 --- a/test/jakarta/el/TestImportHandlerStandardPackages.java +++ b/test/jakarta/el/TestImportHandlerStandardPackages.java @@ -64,9 +64,13 @@ public class TestImportHandlerStandardPackages { try { return Class.forName("java.lang." + c); // Get the class object } catch (ClassNotFoundException e) { - throw new RuntimeException(); + throw new RuntimeException(c); + } catch (Throwable t) { + swallowEnablePreview(c, t); + return null; } }) + .filter(c -> null != c) .filter(c -> Modifier.isPublic(c.getModifiers())) // Exclude non-public classes .map(c -> c.getName().substring(10)) // Back to the class name .map(c -> c.replace('$', '.')) @@ -129,4 +133,25 @@ public class TestImportHandlerStandardPackages { } } } + + + /* + * This is a bit of a hack but there isn't a specific exception that can be + * caught. + */ + private void swallowEnablePreview(String className, Throwable t) { + while (t != null) { + if (t.getMessage() != null && t.getMessage().contains("--enable-preview")) { + return; + } + + Throwable cause = t.getCause(); + if (t == cause) { + break; + } + t = cause; + } + + throw new RuntimeException(className, t); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org