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

junit_test is incompatible with JDK 18+ - "java.lang.UnsupportedOperationException: The Security Manager is deprecated" #16421

Closed
sitaktif opened this issue Oct 7, 2022 · 6 comments

Comments

@sitaktif
Copy link
Contributor

sitaktif commented Oct 7, 2022

Description of the bug:

Running a trivial java_test with JDK 18+ yields the following (with the test failing):

JUnit4 Test Runner
java.lang.UnsupportedOperationException: The Security Manager is deprecated and will be removed in a future release
	at java.base/java.lang.System.setSecurityManager(System.java:418)
	at com.google.testing.junit.runner.junit4.JUnit4Runner.installSecurityManager(JUnit4Runner.java:256)
	at com.google.testing.junit.runner.junit4.JUnit4Runner.run(JUnit4Runner.java:113)
	at com.google.testing.junit.runner.BazelTestRunner.runTestsInSuite(BazelTestRunner.java:148)
	at com.google.testing.junit.runner.BazelTestRunner.main(BazelTestRunner.java:75)

BazelTestRunner exiting with a return value of 1

Having JDK 17 (or older) on the PATH fixes the issue above.

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Sources

WORKSPACE.bazel:

(Empty)

java/example/BUILD.bazel:

java_test(
    name = "ExampleTest",
    srcs = ["ExampleTest.java"],
)

java/example/ExampleTest.java:

package example;

import org.junit.Test;

public class ExampleTest {
  @Test
  public void passes() {
  }
}

Repro command

$ java --version
openjdk 18.0.1
[...]

$ bazel test ... --test_output=errors
[...]
JUnit4 Test Runner
java.lang.UnsupportedOperationException: The Security Manager is deprecated and will be removed in a future release
	at java.base/java.lang.System.setSecurityManager(System.java:418)
	at com.google.testing.junit.runner.junit4.JUnit4Runner.installSecurityManager(JUnit4Runner.java:256)
	at com.google.testing.junit.runner.junit4.JUnit4Runner.run(JUnit4Runner.java:113)
	at com.google.testing.junit.runner.BazelTestRunner.runTestsInSuite(BazelTestRunner.java:148)
	at com.google.testing.junit.runner.BazelTestRunner.main(BazelTestRunner.java:75)

BazelTestRunner exiting with a return value of 1
[...]
INFO: Build completed, 1 test FAILED
[...]

Which operating system are you running Bazel on?=

Macos 12.6

What is the output of bazel info release?

release 5.1.1

@fmeum
Copy link
Collaborator

fmeum commented Oct 8, 2022

You can specify --jvmopt=-Djava.security.manager=allow on the command-line or add common --jvmopt=-Djava.security.manager=allow to your .bazelrc as a workaround that allows you to use JDK 18.

@fmeum
Copy link
Collaborator

fmeum commented Oct 8, 2022

@sgowroji This is essentially a duplicate of #14502, but, in my opinion, a real bug - java_test should work with any released JDK by default.

@sgowroji sgowroji added team-Rules-Java Issues for Java rules untriaged labels Oct 8, 2022
@sgowroji
Copy link
Member

sgowroji commented Oct 8, 2022

Agreed, Thanks for sharing the workaround and marking it to Java team.

@comius
Copy link
Contributor

comius commented Oct 17, 2022

Closing as duplicate of #14502

@comius comius closed this as completed Oct 17, 2022
lsf37 added a commit to jflex-de/jflex that referenced this issue Dec 30, 2022
lsf37 added a commit to jflex-de/jflex that referenced this issue Dec 30, 2022
@toandaominh1997
Copy link

@fmeum This is a great way to fix Security Manager is deprecated on JDK 18

cpovirk added a commit to google/allocation-instrumenter that referenced this issue Dec 14, 2023
Fixes #55

(tested with `JAVA_HOME=$HOME/jdk-22-ea+19 bazel test //... --jvmopt=-Djava.security.manager=allow`, following [these Bazel docs](https://bazel.build/docs/bazel-and-java#config-jvm) and [this Bazel-provided workaround](bazelbuild/bazel#16421))

(piper cl/589180562)
copybara-service bot pushed a commit to google/jni-bind that referenced this issue Feb 26, 2024
It looks like there is no intention to fix this issue.

Details: bazelbuild/bazel#16421
PiperOrigin-RevId: 610239131
copybara-service bot pushed a commit to google/jni-bind that referenced this issue Feb 26, 2024
It looks like there is no intention to fix this issue.

Details: bazelbuild/bazel#16421
PiperOrigin-RevId: 610239131
copybara-service bot pushed a commit to google/jni-bind that referenced this issue Feb 26, 2024
It looks like there is no intention to fix this issue.

Details: bazelbuild/bazel#16421
PiperOrigin-RevId: 610239131
copybara-service bot pushed a commit to google/jni-bind that referenced this issue Feb 26, 2024
It looks like there is no intention to fix this issue.

Details: bazelbuild/bazel#16421
PiperOrigin-RevId: 610239131
copybara-service bot pushed a commit to google/jni-bind that referenced this issue Feb 28, 2024
Due to a bug in Junit this needs to be disabled.

Linux will warn on this error but not crash, however, Darwin will crash.

See bazelbuild/bazel#16421.

PiperOrigin-RevId: 611117548
copybara-service bot pushed a commit to google/jni-bind that referenced this issue Feb 28, 2024
Due to a bug in Junit this needs to be disabled.

Linux will warn on this error but not crash, however, Darwin will crash.

See bazelbuild/bazel#16421.

PiperOrigin-RevId: 611117548
copybara-service bot pushed a commit to google/jni-bind that referenced this issue Feb 28, 2024
Due to a bug in Junit this needs to be disabled.

Linux will warn on this error but not crash, however, Darwin will crash.

See bazelbuild/bazel#16421.

PiperOrigin-RevId: 611117548
copybara-service bot pushed a commit to google/jni-bind that referenced this issue Mar 1, 2024
Due to a bug in Junit this needs to be disabled.

Linux will warn on this error but not crash, however, Darwin will crash.

See bazelbuild/bazel#16421.

PiperOrigin-RevId: 611117548
copybara-service bot pushed a commit to google/jni-bind that referenced this issue Mar 1, 2024
Due to a bug in Junit this needs to be disabled.

Linux will warn on this error but not crash, however, Darwin will crash.

See bazelbuild/bazel#16421.

PiperOrigin-RevId: 611117548
copybara-service bot pushed a commit to google/jni-bind that referenced this issue Mar 4, 2024
Due to a bug in Junit this needs to be disabled.

Linux will warn on this error but not crash, however, Darwin will crash.

See bazelbuild/bazel#16421.

PiperOrigin-RevId: 611117548
copybara-service bot pushed a commit to google/jni-bind that referenced this issue Mar 5, 2024
Due to a bug in Junit this needs to be disabled.

Linux will warn on this error but not crash, however, Darwin will crash.

See bazelbuild/bazel#16421.

PiperOrigin-RevId: 611117548
copybara-service bot pushed a commit to google/jni-bind that referenced this issue Mar 5, 2024
Due to a bug in Junit this needs to be disabled.

Linux will warn on this error but not crash, however, Darwin will crash.

See bazelbuild/bazel#16421.

PiperOrigin-RevId: 611117548
@peakschris
Copy link

I note that this issue is closed, but with Bazel 7.3.1, and jdk 17, and common --jvmopt=-Djava.security.manager=allow, I am still seeing this issue when running junit tests via bazel test:

WARNING: A terminally deprecated method in java.lang.System has been called
WARNING: System::setSecurityManager has been called by com.google.testing.junit.runner.util.GoogleTestSecurityManager (file:/D:/udu/b/xrcdxqdk/external/rules_java++toolchains+remote_java_tools/java_tools/Runner_deploy.jar)
WARNING: Please consider reporting this to the maintainers of com.google.testing.junit.runner.util.GoogleTestSecurityManager
WARNING: System::setSecurityManager will be removed in a future release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants