Thanks to visit codestin.com
Credit goes to github.com

Skip to content

HBASE-27594 [JDK17] SecurityManager is deprecated since JDK17 #6932

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

NihalJain
Copy link
Contributor

@NihalJain NihalJain commented Apr 24, 2025

  • Adds a custom ExitHandler to wrap System.exit calls, preventing JVM termination during tests and throwing an exception instead.
  • Replaces all usages of System.exit calls with ExitHandler.getInstance().exit.
  • Removes TestSecurityManager to reduce deprecated security manager usage.
  • Updates SystemExitRule to use ExitHandler for controlled exit behavior.
  • Removes all usages of System.setSecurityManager / System.getSecurityManager usages in HBase so that it makes our path to future JDK upgrades easier
  • Eliminates warnings related to deprecated System.setSecurityManager and System.getSecurityManager calls.
    WARNING: A terminally deprecated method in java.lang.System has been called
    WARNING: System::setSecurityManager has been called by org.apache.hadoop.hbase.SystemExitRule (file:/Users/nihaljain/code/os/hbase/hbase-common/target/test-classes/)
    WARNING: Please consider reporting this to the maintainers of org.apache.hadoop.hbase.SystemExitRule
    WARNING: System::setSecurityManager will be removed in a future release
    

@NihalJain NihalJain marked this pull request as draft April 24, 2025 05:35
@NihalJain
Copy link
Contributor Author

This is a simple attempt to get rid of System.setSecurityManager / System.getSecurityManager usages in hbase so that it makes our path to future JDK upgrades easier! Lets see what CI says.

@@ -131,6 +131,13 @@

<!-- Make the @SuppressWarnings annotations available to Checkstyle -->
<module name="SuppressWarningsHolder"/>

<!-- Custom check to detect System.exit calls -->
Copy link
Contributor Author

@NihalJain NihalJain Apr 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just FYI: added this checkstyle rule to raise checkstyle an issue if anyone tries to directly use System.exit

@@ -59,6 +61,36 @@ public void testHBaseConfTool() {
}
}

@Test
public void testHBaseConfToolError() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a new test to check for failure scenario, should i drop this?

@Override
public void checkExit(int status) throws SecurityException {
exitCode = status;
public void exit(int status) throws SecurityException {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we still throw a SecurityException?

};
};
}

// Exiting the JVM is not allowed in tests and this exception is thrown instead
// when it is done
public static class SystemExitInTestException extends SecurityException {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we still throw SecurityException?

public class ExitHandler {
private static ExitHandler instance = new ExitHandler();

public static ExitHandler getInstance() {
Copy link
Contributor Author

@NihalJain NihalJain Apr 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should I wrap into Double-Checked Locking. seems overkill for this use case. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some kind of semaphore to ensure that only one thread in a JVM holds a test instance ?
That would also require releasing each test ExitHandler instance explicitily.

return instance;
}

public static void setInstance(ExitHandler handler) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should i let this be called from only tests?

@NihalJain NihalJain requested a review from Copilot April 24, 2025 05:58
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR replaces calls to System.exit with a custom ExitHandler to prevent the JVM from terminating during tests and to eliminate deprecated SecurityManager usage.

  • Replaces all System.exit calls with ExitHandler.getInstance().exit in production and test code
  • Removes TestSecurityManager to further reduce deprecated security manager usage
  • Updates SystemExitRule to leverage ExitHandler for controlled exit behavior

Reviewed Changes

Copilot reviewed 113 out of 114 changed files in this pull request and generated no comments.

Show a summary per file
File Description
hbase-examples/src/main/java/org/apache/hadoop/hbase/mapreduce/SampleUploader.java Replaces System.exit with ExitHandler.getInstance().exit
hbase-examples/src/main/java/org/apache/hadoop/hbase/mapreduce/IndexBuilder.java Replaces System.exit with ExitHandler.getInstance().exit in main and error handling
hbase-endpoint/src/main/java/org/apache/hadoop/hbase/coprocessor/Export.java Updates exit call to use ExitHandler
hbase-diagnostics/src/main/java/org/apache/hadoop/hbase/wal/WALPerformanceEvaluation.java Replaces System.exit with ExitHandler.getInstance().exit in usage and main
hbase-diagnostics/src/main/java/org/apache/hadoop/hbase/master/balancer/LoadBalancerPerformanceEvaluation.java Replaces System.exit with ExitHandler.getInstance().exit
hbase-diagnostics/src/main/java/org/apache/hadoop/hbase/ScanPerformanceEvaluation.java Replaces System.exit with ExitHandler.getInstance().exit in main
hbase-diagnostics/src/main/java/org/apache/hadoop/hbase/PerformanceEvaluation.java Replaces System.exit with ExitHandler.getInstance().exit in error usage and main
hbase-compression/hbase-compression-zstd/src/test/java/org/apache/hadoop/hbase/io/compress/zstd/TestZstdDictionary.java Replaces System.exit with ExitHandler.getInstance().exit in test usage
hbase-common/src/test/java/org/apache/hadoop/hbase/TestSystemExitInTest.java Uses ExitHandler.getInstance().exit instead of System.exit
hbase-common/src/test/java/org/apache/hadoop/hbase/SystemExitRule.java Updates rule to use ExitHandler for controlled test exits
hbase-common/src/main/java/org/apache/hadoop/hbase/util/Random64.java Replaces System.exit with ExitHandler.getInstance().exit on conflict detection
hbase-common/src/main/java/org/apache/hadoop/hbase/util/JenkinsHash.java Replaces System.exit with ExitHandler.getInstance().exit on usage errors
hbase-common/src/main/java/org/apache/hadoop/hbase/util/ExitHandler.java Introduces custom ExitHandler class to centralize exit functionality
hbase-common/src/main/java/org/apache/hadoop/hbase/util/AbstractHBaseTool.java Replaces System.exit with ExitHandler.getInstance().exit before termination
hbase-client/src/test/java/org/apache/hadoop/hbase/ipc/TestCellBlockBuilder.java Updates test exit usage to use ExitHandler.getInstance().exit
hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/mapreduce/MapReduceHFileSplitterJob.java Replaces System.exit with ExitHandler.getInstance().exit in main
hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/RestoreDriver.java Replaces System.exit with ExitHandler.getInstance().exit in main
hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/BackupDriver.java Replaces System.exit with ExitHandler.getInstance().exit in main
Files not reviewed (1)
  • hbase-checkstyle/src/main/resources/hbase/checkstyle.xml: Language not supported

@NihalJain NihalJain marked this pull request as ready for review April 24, 2025 06:52
@NihalJain
Copy link
Contributor Author

NihalJain commented Apr 24, 2025

Built code locally, started a standalone hbase cluster and verified exit codes for HBaseConfTool are as expected.

Screenshot:
Screenshot 2025-04-24 at 12 22 10 PM

@Apache-HBase

This comment has been minimized.

@Apache-HBase

This comment has been minimized.

@Apache-HBase

This comment has been minimized.

@Apache-HBase

This comment has been minimized.

@NihalJain
Copy link
Contributor Author

Failures are not related. Ran the test locally, it passed.

Screenshot 2025-04-25 at 3 42 39 PM

@Apache-HBase
Copy link

🎊 +1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 36s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 1s No case conflicting files found.
+0 🆗 codespell 0m 0s codespell was not available.
+0 🆗 detsecrets 0m 0s detect-secrets was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
+1 💚 hbaseanti 0m 0s Patch does not have any anti-patterns.
_ master Compile Tests _
+0 🆗 mvndep 0m 12s Maven dependency ordering for branch
+1 💚 mvninstall 3m 13s master passed
+1 💚 compile 10m 45s master passed
+1 💚 checkstyle 1m 15s master passed
+1 💚 spotbugs 9m 8s master passed
+1 💚 spotless 0m 46s branch has no errors when running spotless:check.
_ Patch Compile Tests _
+0 🆗 mvndep 0m 11s Maven dependency ordering for patch
+1 💚 mvninstall 3m 2s the patch passed
+1 💚 compile 10m 38s the patch passed
+1 💚 javac 0m 8s hbase-checkstyle in the patch passed.
+1 💚 javac 0m 39s hbase-common generated 0 new + 67 unchanged - 5 fixed = 67 total (was 72)
+1 💚 javac 0m 45s hbase-client in the patch passed.
+1 💚 javac 0m 20s hbase-zookeeper generated 0 new + 48 unchanged - 1 fixed = 48 total (was 49)
+1 💚 javac 0m 18s hbase-replication in the patch passed.
+1 💚 javac 0m 23s hbase-http in the patch passed.
+1 💚 javac 0m 24s hbase-procedure in the patch passed.
-0 ⚠️ javac 3m 6s /results-compile-javac-hbase-server.txt hbase-server generated 1 new + 192 unchanged - 1 fixed = 193 total (was 193)
-0 ⚠️ javac 0m 34s /results-compile-javac-hbase-mapreduce.txt hbase-mapreduce generated 2 new + 196 unchanged - 2 fixed = 198 total (was 198)
+1 💚 javac 0m 25s hbase-diagnostics in the patch passed.
+1 💚 javac 0m 41s hbase-thrift in the patch passed.
+1 💚 javac 0m 24s hbase-endpoint in the patch passed.
+1 💚 javac 0m 28s hbase-backup in the patch passed.
+1 💚 javac 0m 30s hbase-it in the patch passed.
+1 💚 javac 0m 32s hbase-rest in the patch passed.
+1 💚 javac 0m 24s hbase-examples generated 0 new + 8 unchanged - 5 fixed = 8 total (was 13)
+1 💚 javac 0m 20s hbase-hbtop in the patch passed.
+1 💚 javac 0m 18s hbase-compression-zstd in the patch passed.
+1 💚 blanks 0m 0s The patch has no blanks issues.
-0 ⚠️ checkstyle 1m 11s /results-checkstyle-root.txt root: The patch generated 3 new + 164 unchanged - 2 fixed = 167 total (was 166)
+1 💚 xmllint 0m 1s No new issues.
+1 💚 spotbugs 11m 33s the patch passed
+1 💚 hadoopcheck 12m 13s Patch does not cause any errors with Hadoop 3.3.6 3.4.0.
+1 💚 spotless 0m 47s patch has no errors when running spotless:check.
_ Other Tests _
+1 💚 asflicense 2m 27s The patch does not generate ASF License warnings.
78m 50s
Subsystem Report/Notes
Docker ClientAPI=1.43 ServerAPI=1.43 base: https://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-6932/4/artifact/yetus-general-check/output/Dockerfile
GITHUB PR #6932
Optional Tests dupname asflicense javac spotbugs checkstyle codespell detsecrets compile hadoopcheck hbaseanti spotless xmllint
uname Linux bfdf36491ca2 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/hbase-personality.sh
git revision master / 20fc7b0
Default Java Eclipse Adoptium-17.0.11+9
Max. process+thread count 86 (vs. ulimit of 30000)
modules C: hbase-checkstyle hbase-common hbase-client hbase-zookeeper hbase-replication hbase-http hbase-procedure hbase-server hbase-mapreduce hbase-diagnostics hbase-thrift hbase-endpoint hbase-backup hbase-it hbase-rest hbase-examples hbase-hbtop hbase-compression/hbase-compression-zstd U: .
Console output https://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-6932/4/console
versions git=2.34.1 maven=3.9.8 spotbugs=4.7.3 xmllint=20913
Powered by Apache Yetus 0.15.0 https://yetus.apache.org

This message was automatically generated.

@Apache-HBase
Copy link

🎊 +1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 33s Docker mode activated.
-0 ⚠️ yetus 0m 6s Unprocessed flag(s): --brief-report-file --spotbugs-strict-precheck --author-ignore-list --blanks-eol-ignore-file --blanks-tabs-ignore-file --quick-hadoopcheck
_ Prechecks _
_ master Compile Tests _
+0 🆗 mvndep 0m 10s Maven dependency ordering for branch
+1 💚 mvninstall 3m 12s master passed
+1 💚 compile 5m 50s master passed
+1 💚 javadoc 4m 18s master passed
+1 💚 shadedjars 5m 56s branch has no errors when building our shaded downstream artifacts.
_ Patch Compile Tests _
+0 🆗 mvndep 0m 12s Maven dependency ordering for patch
+1 💚 mvninstall 3m 1s the patch passed
+1 💚 compile 5m 45s the patch passed
+1 💚 javac 0m 8s hbase-checkstyle in the patch passed.
+1 💚 javac 0m 20s hbase-common generated 0 new + 3 unchanged - 9 fixed = 3 total (was 12)
+1 💚 javac 0m 20s hbase-client in the patch passed.
+1 💚 javac 0m 14s hbase-zookeeper generated 0 new + 3 unchanged - 2 fixed = 3 total (was 5)
+1 💚 javac 0m 13s hbase-replication in the patch passed.
+1 💚 javac 0m 17s hbase-http in the patch passed.
+1 💚 javac 0m 14s hbase-procedure in the patch passed.
+1 💚 javac 0m 57s hbase-server generated 0 new + 13 unchanged - 6 fixed = 13 total (was 19)
+1 💚 javac 0m 19s hbase-mapreduce generated 0 new + 0 unchanged - 24 fixed = 0 total (was 24)
+1 💚 javac 0m 18s hbase-diagnostics in the patch passed.
+1 💚 javac 0m 25s hbase-thrift in the patch passed.
+1 💚 javac 0m 17s hbase-endpoint in the patch passed.
+1 💚 javac 0m 18s hbase-backup in the patch passed.
+1 💚 javac 0m 20s hbase-it in the patch passed.
+1 💚 javac 0m 20s hbase-rest in the patch passed.
+1 💚 javac 0m 18s hbase-examples generated 0 new + 0 unchanged - 5 fixed = 0 total (was 5)
+1 💚 javac 0m 13s hbase-hbtop in the patch passed.
+1 💚 javac 0m 14s hbase-compression-zstd in the patch passed.
+1 💚 javadoc 4m 16s the patch passed
+1 💚 shadedjars 5m 50s patch has no errors when building our shaded downstream artifacts.
_ Other Tests _
+1 💚 unit 0m 9s hbase-checkstyle in the patch passed.
+1 💚 unit 2m 10s hbase-common in the patch passed.
+1 💚 unit 1m 35s hbase-client in the patch passed.
+1 💚 unit 0m 43s hbase-zookeeper in the patch passed.
+1 💚 unit 0m 27s hbase-replication in the patch passed.
+1 💚 unit 0m 50s hbase-http in the patch passed.
+1 💚 unit 1m 30s hbase-procedure in the patch passed.
+1 💚 unit 210m 44s hbase-server in the patch passed.
+1 💚 unit 21m 30s hbase-mapreduce in the patch passed.
+1 💚 unit 5m 32s hbase-diagnostics in the patch passed.
+1 💚 unit 6m 59s hbase-thrift in the patch passed.
+1 💚 unit 3m 48s hbase-endpoint in the patch passed.
+1 💚 unit 16m 0s hbase-backup in the patch passed.
+1 💚 unit 1m 15s hbase-it in the patch passed.
+1 💚 unit 5m 8s hbase-rest in the patch passed.
+1 💚 unit 2m 59s hbase-examples in the patch passed.
+1 💚 unit 0m 58s hbase-hbtop in the patch passed.
+1 💚 unit 6m 6s hbase-compression-zstd in the patch passed.
336m 1s
Subsystem Report/Notes
Docker ClientAPI=1.43 ServerAPI=1.43 base: https://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-6932/4/artifact/yetus-jdk17-hadoop3-check/output/Dockerfile
GITHUB PR #6932
Optional Tests javac javadoc unit compile shadedjars
uname Linux 320fae4bc836 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/hbase-personality.sh
git revision master / 20fc7b0
Default Java Eclipse Adoptium-17.0.11+9
Test Results https://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-6932/4/testReport/
Max. process+thread count 5396 (vs. ulimit of 30000)
modules C: hbase-checkstyle hbase-common hbase-client hbase-zookeeper hbase-replication hbase-http hbase-procedure hbase-server hbase-mapreduce hbase-diagnostics hbase-thrift hbase-endpoint hbase-backup hbase-it hbase-rest hbase-examples hbase-hbtop hbase-compression/hbase-compression-zstd U: .
Console output https://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-6932/4/console
versions git=2.34.1 maven=3.9.8
Powered by Apache Yetus 0.15.0 https://yetus.apache.org

This message was automatically generated.

@NihalJain NihalJain requested review from stoty, Apache9 and ndimiduk May 7, 2025 12:09
@NihalJain
Copy link
Contributor Author

WDYT about this approach? @stoty @ndimiduk @Apache9

@stoty
Copy link
Contributor

stoty commented May 7, 2025

Two general comments:

The description is too generic. SecurityManager is used in other places, mainly via HAdoop/UGI, which this patch does not fix.
I suggest rewording it to reflect that this change is specific to the SecurityManager usage for tests with system.exit.

My other questions regarding JVM re-use in tests:
Have you considered that the ExitHandler is JVM global ? Could that cause problems with test classes that may trigger exitHandler from multiple tests methods ? Could that be an issue when the JVM is re-used for the non-needsowncluster tests ?

@Apache9
Copy link
Contributor

Apache9 commented May 7, 2025

What if there are System.exit calls in the libraries we used? Like hadoop?

@stoty
Copy link
Contributor

stoty commented May 7, 2025

Hadoop uses similar ExitHandler mechanism(s).
We're doing something very similar (Replacing remaining SecurtityManager usages for system.exit) in Hadoop for 3.5.

But you're right in that Hadoop should expose this functionality in a standard manner so that we can set this in our tests for Hadoop jobs.

Unfortunately I'm not aware of a universal solution.

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

Successfully merging this pull request may close these issues.

4 participants