Posted August 15, 201411 yr I have an access transformer in my mod, and it works perfectly in the developer environment. However, it fails to even load in the compiled copy of the game, causing a prompt IllegalAccessError and crash. Having reverse-engineered the access-transformer loading code, I have been left stumped. Here is what I get in my loading logs: [15:03:48] [main/DEBUG] [FML/]: Examining for coremod candidacy Reika-1.0.jar [15:03:48] [main/DEBUG] [FML/]: Not found coremod data in Reika-1.0.jar And here is the code that loads the Access Transformers (collected from CoreModManager.class, ModAccessTransformer.class, and AccessTransformer.class): private static void discoverCoreMods(File mcDir, LaunchClassLoader classLoader) { FMLRelaunchLog.fine("Discovering coremods"); File coreMods = setupCoreModDir(mcDir); FilenameFilter ff = new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".jar"); } }; File[] coreModList = coreMods.listFiles(ff); File versionedModDir = new File(coreMods, FMLInjectionData.mccversion); if (versionedModDir.isDirectory()) { File[] versionedCoreMods = versionedModDir.listFiles(ff); coreModList = ObjectArrays.concat(coreModList, versionedCoreMods, File.class); } coreModList = FileListHelper.sortFileList(coreModList); for (File coreMod : coreModList) { FMLRelaunchLog.fine("Examining for coremod candidacy %s", coreMod.getName()); JarFile jar = null; Attributes mfAttributes; try { jar = new JarFile(coreMod); if (jar.getManifest() == null) { // Not a coremod and no access transformer list continue; } ModAccessTransformer.addJar(jar); mfAttributes = jar.getManifest().getMainAttributes(); } catch (IOException ioe) { FMLRelaunchLog.log(Level.ERROR, ioe, "Unable to read the jar file %s - ignoring", coreMod.getName()); continue; } finally { if (jar != null) { try { jar.close(); } catch (IOException e) { // Noise } } } String cascadedTweaker = mfAttributes.getValue("TweakClass"); if (cascadedTweaker != null) { FMLRelaunchLog.info("Loading tweaker %s from %s", cascadedTweaker, coreMod.getName()); Integer sortOrder = Ints.tryParse(Strings.nullToEmpty(mfAttributes.getValue("TweakOrder"))); sortOrder = (sortOrder == null ? Integer.valueOf(0) : sortOrder); handleCascadingTweak(coreMod, jar, cascadedTweaker, classLoader, sortOrder); loadedCoremods.add(coreMod.getName()); continue; } String fmlCorePlugin = mfAttributes.getValue("FMLCorePlugin"); if (fmlCorePlugin == null) { // Not a coremod FMLRelaunchLog.fine("Not found coremod data in %s", coreMod.getName()); continue; } public static void addJar(JarFile jar) throws IOException { AccessTransformer at = new AccessTransformer(jar); if (!at.isEmpty()) { embedded.add(at); } } AccessTransformer(JarFile jar) throws IOException { Manifest manifest = jar.getManifest(); String atList = manifest.getMainAttributes().getValue("FMLAT"); if (atList == null) return; for (String at : atList.split(" ")) { JarEntry jarEntry = jar.getJarEntry("META-INF/"+at); if (jarEntry != null) { processATFile(new JarByteSource(jar,jarEntry).asCharSource(Charsets.UTF_); } } FMLRelaunchLog.fine("Loaded %d rules from AccessTransformer mod jar file %s\n", modifiers.size(), jar.getName()); } As you can see by looking at the code, the fact that I get the first line in my console proves it tries to load my file, and the second line shows that the execution makes it to the line FMLRelaunchLog.fine("Not found coremod data in %s", coreMod.getName()); As you can also see, this line is only reached if jar.getManifest() does not return null. Digging into the instantiation of an AccessTransformer object, it is clear that what is happening is that "atList", the string returned when reading the manifest parameter for "FMLAT", is null, as that is the only thing that would cause the logs to not contain the message "loaded X rules from access transformer...". ----------------------------------------------------------------------------------------------------------------------- So, in short, it is clear that the Manifest file is being found, but the fetch for the FMLAT property returns null. Yet here is my manifest file: Manifest-Version: 1.0 FMLAT: DragonAPI_at.cfg I looked into the java documentation, and I found that it says it requires the manifest file be encoded in UTF-8, rather than ANSI (the windows standard). I tried this, and the game fails to even load my jar, instead printing this: [main/ERROR] [FML/]: Unable to read the jar file Reika-1.0.jar - ignoring java.io.IOException: invalid header field name: Manifest-Version at java.util.jar.Attributes.read(Attributes.java:433) ~[?:1.7.0_55] at java.util.jar.Manifest.read(Manifest.java:199) ~[?:1.7.0_55] at java.util.jar.Manifest.<init>(Manifest.java:69) ~[?:1.7.0_55] at java.util.jar.JarFile.getManifestFromReference(JarFile.java:180) ~[?:1.7.0_55] at java.util.jar.JarFile.getManifest(JarFile.java:166) ~[?:1.7.0_55] at cpw.mods.fml.relauncher.CoreModManager.discoverCoreMods(CoreModManager.java:244) [forge-1.7.10-10.13.0.1180.jar:?] What is going on, and how do I fix it? I have asked multiple people, and so far noone has any idea. Follow my mod(s) here: http://www.minecraftforum.net/topic/1969694-
August 15, 201411 yr In some editors you can save in UTF-8 without the bytecode marks at the beginning of the file. It's my observation, however, than ANSI(7-bit ASCII) is a proper subset of UTF-8 and unless you are putting in characters outside the 127 standard ASCII code, UTF-8 is the same as ANSI. -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
August 15, 201411 yr Author In some editors you can save in UTF-8 without the bytecode marks at the beginning of the file. It's my observation, however, than ANSI(7-bit ASCII) is a proper subset of UTF-8 and unless you are putting in characters outside the 127 standard ASCII code, UTF-8 is the same as ANSI. I have done nothing unusual with these files, and have tried all three of my text editors: Windows Notepad, Notepad++, and EditPad Lite. Follow my mod(s) here: http://www.minecraftforum.net/topic/1969694-
August 16, 201411 yr Author Upon further debugging, using a custom script to read my mod JAR in the dev environment (not to actually load it, just parse it for display): try { JarFile f = new JarFile("C:/Users/Reika/Downloads/mmc-stable-win32/MultiMC/instances/1.7 Test/minecraft/mods/Reika-1.0.jar"); Manifest mf = f.getManifest(); ReikaJavaLibrary.pConsole(mf.getEntries()); f.close(); } catch (Exception e) { throw new RuntimeException(e); } The result is an empty map "{}", with no exceptions being raised. This is obviously the source of my problem, but why is the manifest file found yet not readable!? EDIT: Further modification and testing, with this horrible block of code (which basically recreates the Manifest reader) try { String s = "C:/Users/Reika/Downloads/mmc-stable-win32/MultiMC/instances/1.7 Test/minecraft/mods/Reika-1.0.jar"; JarFile f = new JarFile(s); Manifest mf = f.getManifest(); ReikaJavaLibrary.pConsole(mf.getEntries()); ZipEntry e = f.getEntry(f.MANIFEST_NAME); ReikaJavaLibrary.pConsole(e); ZipFile z = new ZipFile(s); InputStream is = z.getInputStream(e); byte[] data = IOUtils.readFully(is, (int)e.getSize(), true); ReikaJavaLibrary.pConsole(Arrays.toString(data)); ReikaJavaLibrary.pConsole(new String(data)); ByteArrayInputStream b = new ByteArrayInputStream(data); Class clazz = Class.forName("java.util.jar.Manifest$FastInputStream"); Constructor con = clazz.getDeclaredConstructor(InputStream.class); con.setAccessible(true); Object fast = con.newInstance(b); Class[] params = new Class[] {byte[].class}; Method readline = clazz.getDeclaredMethod("readLine", params); readline.setAccessible(true); byte[] buf = new byte[512]; int ret = (Integer)readline.invoke(fast, buf); int count = 0; ReikaJavaLibrary.pConsole(count+": "+ret); while (ret != -1) { count++; ret = (Integer)readline.invoke(fast, buf); ReikaJavaLibrary.pConsole(count+": "+ret); } f.close(); z.close(); } catch (Exception e) { throw new RuntimeException(e); } And I get what I was expecting! {} of class java.util.HashMap META-INF/MANIFEST.MF of class java.util.jar.JarFile$JarFileEntry [77, 97, 110, 105, 102, 101, 115, 116, 45, 86, 101, 114, 115, 105, 111, 110, 58, 32, 49, 46, 48, 13, 10, 70, 77, 76, 65, 84, 58, 32, 68, 114, 97, 103, 111, 110, 65, 80, 73, 95, 97, 116, 46, 99, 102, 103, 13, 10] Manifest-Version: 1.0 FMLAT: DragonAPI_at.cfg 0: 23 1: 25 2: -1 So, in other words, it parses the file fine, yet somehow does not build entries??! Follow my mod(s) here: http://www.minecraftforum.net/topic/1969694-
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.