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

ForkJoinPool behavior change in Java 11 breaks ComposableSecurityManagerPolicyTest #36

Closed
guw opened this issue Dec 31, 2019 · 0 comments

Comments

@guw
Copy link
Contributor

guw commented Dec 31, 2019

ComposableSecurityManagerPolicyTest.testParallelStreamsThreadingWithSecurityManager fails with Java 11. It looks like a workaround for ForkJoinPool (in ComposableSecurityManagerPolicy) no longer works properly.

I found a Stack Overflow post which seems to confirm a change between JDK 8 and JDK 11.

Here is the error output from running the test with Java 11:

testParallelStreamsThreadingWithSecurityManager(io.takari.builder.enforcer.ComposableSecurityManagerPolicyTest)  Time elapsed: 0.019 s  <<< FAILURE!
java.lang.AssertionError:

Expecting:
  <["access denied ("java.util.PropertyPermission" "not.allowed" "read")",
    "access denied ("java.util.PropertyPermission" "allowed" "read")",
    "access denied ("java.util.PropertyPermission" "not.allowed" "read")",
    null,
    "access denied ("java.util.PropertyPermission" "not.allowed" "read")",
    "access denied ("java.util.PropertyPermission" "allowed" "read")"]>
to contain exactly (and in same order):
  <["nope", null, "nope", null, "nope", null]>
but some elements were not found:
  <["nope", "nope", null, "nope", null]>
and others were not expected:
  <["access denied ("java.util.PropertyPermission" "not.allowed" "read")",
    "access denied ("java.util.PropertyPermission" "allowed" "read")",
    "access denied ("java.util.PropertyPermission" "not.allowed" "read")",
    "access denied ("java.util.PropertyPermission" "not.allowed" "read")",
    "access denied ("java.util.PropertyPermission" "allowed" "read")"]>

	at io.takari.builder.enforcer.ComposableSecurityManagerPolicyTest.testParallelStreamsThreadingWithSecurityManager(ComposableSecurityManagerPolicyTest.java:115)

A potential fix for the test is to simply wrap any async execution with a PrivilegedAction and run it within the outer's AccessControlContext.

testParallelStreamsThreadingWithSecurityManager (line 108):

      AccessControlContext accessControlContext = AccessController.getContext();
      List<String> exs1 = work.parallelStream().map(x -> {
        return AccessController.doPrivileged((PrivilegedAction<Exception>) () -> {
          try {
            return x.call();
          } catch (Exception e) {
            return e;
          }
        }, accessControlContext);
      }).map(e -> e != null ? e.getMessage() : null).collect(Collectors.toList());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant