8166860: Add magic number to jmod file
Reviewed-by: alanb, jjg
This commit is contained in:
parent
512c42b9ac
commit
a3f3f797b5
langtools
make/tools/crules
src/jdk.compiler/share/classes/com/sun/tools/javac
test/tools/javac/T8003967
@ -111,6 +111,8 @@ public class MutableFieldsAnalyzer extends AbstractCodingRulesAnalyzer {
|
||||
"loadMethod");
|
||||
ignoreFields("com.sun.tools.javac.util.JDK9Wrappers$VMHelper",
|
||||
"vmClass", "getRuntimeArgumentsMethod");
|
||||
ignoreFields("com.sun.tools.javac.util.JDK9Wrappers$JmodFile",
|
||||
"jmodFileClass", "checkMagicMethod");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -78,6 +78,7 @@ import com.sun.tools.javac.resources.CompilerProperties.Errors;
|
||||
import com.sun.tools.javac.resources.CompilerProperties.Warnings;
|
||||
import com.sun.tools.javac.util.DefinedBy;
|
||||
import com.sun.tools.javac.util.DefinedBy.Api;
|
||||
import com.sun.tools.javac.util.JDK9Wrappers;
|
||||
import com.sun.tools.javac.util.ListBuffer;
|
||||
import com.sun.tools.javac.util.Log;
|
||||
import com.sun.tools.javac.jvm.ModuleNameReader;
|
||||
@ -1103,6 +1104,11 @@ public class Locations {
|
||||
|
||||
if (p.getFileName().toString().endsWith(".jmod")) {
|
||||
try {
|
||||
// check if the JMOD file is valid
|
||||
JDK9Wrappers.JmodFile.checkMagic(p);
|
||||
|
||||
// No JMOD file system. Use JarFileSystem to
|
||||
// workaround for now
|
||||
FileSystem fs = fileSystems.get(p);
|
||||
if (fs == null) {
|
||||
URI uri = URI.create("jar:" + p.toUri());
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
package com.sun.tools.javac.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.file.Path;
|
||||
@ -367,4 +368,41 @@ public class JDK9Wrappers {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper class for new method in jdk.internal.jmod.JmodFile
|
||||
*/
|
||||
public static final class JmodFile {
|
||||
public static final String JMOD_FILE_CLASSNAME = "jdk.internal.jmod.JmodFile";
|
||||
|
||||
public static void checkMagic(Path file) throws IOException {
|
||||
try {
|
||||
init();
|
||||
checkMagicMethod.invoke(null, file);
|
||||
} catch (InvocationTargetException ex) {
|
||||
if (ex.getCause() instanceof IOException) {
|
||||
throw IOException.class.cast(ex.getCause());
|
||||
}
|
||||
throw new Abort(ex);
|
||||
} catch (IllegalAccessException | IllegalArgumentException | SecurityException ex) {
|
||||
throw new Abort(ex);
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------
|
||||
|
||||
private static Class<?> jmodFileClass = null;
|
||||
private static Method checkMagicMethod = null;
|
||||
|
||||
private static void init() {
|
||||
if (jmodFileClass == null) {
|
||||
try {
|
||||
jmodFileClass = Class.forName(JMOD_FILE_CLASSNAME, false, null);
|
||||
checkMagicMethod = jmodFileClass.getDeclaredMethod("checkMagic", Path.class);
|
||||
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException ex) {
|
||||
throw new Abort(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -118,6 +118,8 @@ public class DetectMutableStaticFields {
|
||||
"loadMethod");
|
||||
ignore("com/sun/tools/javac/util/JDK9Wrappers$VMHelper",
|
||||
"vmClass", "getRuntimeArgumentsMethod");
|
||||
ignore("com/sun/tools/javac/util/JDK9Wrappers$JmodFile",
|
||||
"jmodFileClass", "checkMagicMethod");
|
||||
}
|
||||
|
||||
private final List<String> errors = new ArrayList<>();
|
||||
|
Loading…
x
Reference in New Issue
Block a user