Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zeichenreihe opened this issue Mar 27, 2023 · 1 comment
Open

Comments

@zeichenreihe
Copy link

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.

FileObject outResource = this.ap.getProcessingEnvironment().getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", fileName);
this.ap.printMessage(MessageType.INFO, "Writing " + description + " to " + new File(outResource.toUri()).getAbsolutePath());

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
Copy link
Member

Mumfrey commented Apr 5, 2023

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.

zeichenreihe added a commit to zeichenreihe/sponge-mixin that referenced this issue May 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants