Mixin icon indicating copy to clipboard operation
Mixin copied to clipboard

Mixin fails if `FileObject.toUri()` doesn't represent a real file.

Open zeichenreihe opened this issue 2 years ago • 0 comments

Mixin makes assumptions about the FileObject returned from the Java compilation. It assumes that the URI returned by .toUri() can be passed into new File(URI), which requires that the URI represents a real file (check the source of new File(URI)). This may be most of the time true, but it can fail, and it does for me. My implementation of the JavaFileManager keeps the files in memory, for faster compilation. The .toUri() method only "Returns a URI identifying this file object." (see the Javadoc for it), it does not require the URI to have the file:// scheme.

https://github.com/FabricMC/Mixin/blob/921353610dfe0a2860c89262f306b79b8b95c199/src/ap/java/org/spongepowered/tools/obfuscation/ReferenceManager.java#L158-L159

java.lang.IllegalArgumentException: URI scheme is not "file"
        at java.io.File.<init>(File.java:423)
        at org.spongepowered.tools.obfuscation.ReferenceManager.newWriter(ReferenceManager.java:158)
        at org.spongepowered.tools.obfuscation.ReferenceManager.write(ReferenceManager.java:131)
        at org.spongepowered.tools.obfuscation.ObfuscationManager.writeReferences(ObfuscationManager.java:126)
        at org.spongepowered.tools.obfuscation.AnnotatedMixins.writeReferences(AnnotatedMixins.java:345)
        at org.spongepowered.tools.obfuscation.MixinObfuscationProcessorTargets.postProcess(MixinObfuscationProcessorTargets.java:87)
        at org.spongepowered.tools.obfuscation.MixinObfuscationProcessorTargets.process(MixinObfuscationProcessorTargets.java:67)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:802)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$200(JavacProcessingEnvironment.java:91)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment$DiscoveredProcessors$ProcessorStateIterator.runContributingProcs(JavacProcessingEnvironment.java:635)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1041)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1206)
        at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
        at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)
        at com.sun.tools.javac.main.Main.compile(Main.java:523)
        at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
        at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
...

Suggested fix:

-        this.ap.printMessage(MessageType.INFO, "Writing " + description + " to " + new File(outResource.toUri()).getAbsolutePath());
+        this.ap.printMessage(MessageType.INFO, "Writing " + description + " to " + outResource.toUri().toString());

zeichenreihe avatar Jul 30 '23 01:07 zeichenreihe