SpongePowered / Mixin

Mixin is a trait/mixin and bytecode weaving framework for Java using ASM
MIT License
1.37k stars 185 forks source link

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

Closed zeichenreihe closed 3 weeks ago

zeichenreihe commented 1 year ago

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 javadoc for it), it does not require the URI to have the file scheme.

Fix: Either remove the logging, or make it print the URI directly, there's no need to force it into being a real file.

https://github.com/SpongePowered/Mixin/blob/1e1aa7fb52dec78630f3f2f53fd70a4c496a7d66/src/ap/java/org/spongepowered/tools/obfuscation/ReferenceManager.java#L157-L158

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)
...
Mumfrey commented 1 year ago

Fix: Either remove the logging, or make it print the URI directly, there's no need to force it into being a real file.

It only casts to file so that it can emit the full canonical location, but it could check first if it's a file before doing so.