-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add additional check to ensure Recaf runs with a JDK and not a JRE
For now we'll just exit with a special exit code, since we crash anyways. Longer term we will want to just disable features that rely on the JDK specific code rather than exit. This includes things like: - Attaching to remote processes (jdk.attach module does not exist in JREs) - Recompiling (JavacCompiler interface has no implementations)
- Loading branch information
Showing
4 changed files
with
43 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
recaf-core/src/main/java/software/coley/recaf/util/JdkValidation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package software.coley.recaf.util; | ||
|
||
import org.slf4j.Logger; | ||
import software.coley.recaf.ExitCodes; | ||
import software.coley.recaf.ExitDebugLoggingHook; | ||
import software.coley.recaf.analytics.logging.Logging; | ||
|
||
/** | ||
* JDK vs JRE validation utils. | ||
* | ||
* @author Matt Coley | ||
*/ | ||
public class JdkValidation { | ||
private static final Logger logger = Logging.get(JdkValidation.class); | ||
|
||
/** | ||
* Applies a few assorted checks to ensure we are running on a JDK and not a JRE. | ||
*/ | ||
public static void validateJdk() { | ||
try { | ||
Class.forName("com.sun.tools.attach.VirtualMachine"); | ||
} catch (ClassNotFoundException ex) { | ||
logger.error("Recaf must be run with a JDK, but was run with a JRE: " + System.getProperty("java.home")); | ||
ExitDebugLoggingHook.exit(ExitCodes.ERR_NOT_A_JDK); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters