diff -r ee4857e4fa85 -r abd777fa486c langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JDK9Wrappers.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JDK9Wrappers.java Tue Oct 04 18:43:36 2016 -0700 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JDK9Wrappers.java Tue Oct 04 18:56:03 2016 -0700 @@ -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 @@ } } } + + /** + * 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); + } + } + } + } }