1
1
/*
2
- * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -63,7 +63,7 @@ private void testRuntimePermission(boolean permitInetAddressResolver) throws Exc
63
63
ServiceConfigurationError sce =
64
64
Assert .expectThrows (ServiceConfigurationError .class ,
65
65
() -> InetAddress .getByName ("javaTest.org" ));
66
- LOGGER . info ("Got ServiceConfigurationError: " + sce );
66
+ System . err . println ("Got ServiceConfigurationError: " + sce );
67
67
Throwable cause = sce .getCause ();
68
68
Assert .assertTrue (cause instanceof SecurityException );
69
69
Assert .assertTrue (cause .getMessage ().contains (RUNTIME_PERMISSION_NAME ));
@@ -78,23 +78,25 @@ static class TestSecurityManager extends SecurityManager {
78
78
79
79
public TestSecurityManager (boolean permitInetAddressResolver ) {
80
80
this .permitInetAddressResolver = permitInetAddressResolver ;
81
- LOGGER . info ("inetAddressResolverProvider permission is " +
82
- (permitInetAddressResolver ? "granted" : "not granted" ));
81
+ System . err . println ("inetAddressResolverProvider permission is " +
82
+ (permitInetAddressResolver ? "granted" : "not granted" ));
83
83
}
84
84
85
85
@ Override
86
86
public void checkPermission (Permission permission ) {
87
87
if (permission instanceof RuntimePermission ) {
88
- LOGGER .info ("Checking RuntimePermission: " + permission );
89
88
if (RUNTIME_PERMISSION_NAME .equals (permission .getName ()) && !permitInetAddressResolver ) {
90
- LOGGER . info ("Denying '" + RUNTIME_PERMISSION_NAME + "' permission" );
89
+ System . err . println ("Denying '" + RUNTIME_PERMISSION_NAME + "' permission" );
91
90
throw new SecurityException ("Access Denied: " + RUNTIME_PERMISSION_NAME );
92
- }
91
+ } else {
92
+ // Do not do anything for non-matching Permission. Otherwise the test
93
+ // has a chance to re-enter here recursively, e.g. due to permission
94
+ // checks during class load. This would eventually overflow the stack.
95
+ }
93
96
}
94
97
}
95
98
}
96
99
97
100
private static final String RUNTIME_PERMISSION_NAME = "inetAddressResolverProvider" ;
98
- private static final Logger LOGGER = Logger .getLogger (RuntimePermissionTest .class .getName ());
99
101
100
102
}
0 commit comments