Running Refaster and error-prone 2.3.1 on Java 8

350 views
Skip to first unread message

jbluet...@gmail.com

unread,
Jun 18, 2018, 6:06:44 PM6/18/18
to error-prone-discuss
Hi all,

I am currently trying to use Refaster 2.3.1 and error-prone 2.3.1 with Java 8, with the ultimate aim of building a Gradle plugin for Refaster that would work across a number of recent error-prone/Refaster versions and all JDKs version 8+. However, I’m having limited success so far getting the combination of Refaster, error-prone and Java above working, and I was hoping that someone could help me understand where my lack of understanding is and how I could potentially move forward.

There are at least two facets to my problem. Firstly, when I look at the current instructions over at http://errorprone.info/docs/refaster, I notice that they work on my machine up to Refaster version 2.1.1. However, any version equal to or greater than 2.1.2 fails to work, which I understand is due to a change in commit [1] which was introduced to support Java 9.

Secondly, when I look at the alternative instructions for running Refaster over at [2], I see that it suggests downloading and running a custom version of javac as a jar, but I’m confused as to how I’m supposed to run it, because running just `javac` on my machine uses my default installed Java 8 javac.

My Google searches brought me to [3], but it wasn’t clear to me that there was any useful information other than building a patched error-prone compiler from scratch, which I admit I feel rather iffy doing.

Can someone help me understand how to move forward with all this?

Cheers,
Jonathan

P.S. The OS I’m running on is Windows 7, and my installed JDK is Oracle JDK version 1.8.0_161, specifically:
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

Thomas Broyer

unread,
Jun 19, 2018, 4:49:43 AM6/19/18
to error-prone-discuss
I think neither doc is up-to-date and/or correct.
  • the website is out of date (talks about 2.1.1, and indeed gives directions for 2.1.1, that no longer work)
  • the examples/refaster/README.md doesn't make use of javac-9+181-r4173-1.jar, as that one is only needed if you use JDK 8 but the instructions clearly are targeting JDK 9; and should pass the refaster JAR in the -processorpath for the -Xplugin to work, not the -cp.
I haven't tried it but I'd assume that with Java 8 you'd have to prepend the custom javac JAR to the bootclasspath, as when running ErrorProne itself, so using something like -J-Xbootclasspath/p:javac-9+181-r4173-1.jar. I'm really not sure that would work though…

In a Gradle plugin, I'd suggest building on my net.ltgt.errorprone plugin for Java 8 (and possibly Java 9) and "simply" adding the refaster JAR to the annotationProcessorPath and the -Xplugin argument to the options.compilerArgs (if that doesn't work, then you could at least use the same trick to get the javac-9+181-r4173-1.jar in the classloader; maybe have a look at https://github.com/tbroyer/gradle-errorprone-plugin/commit/80a7bd73957e33370a27af1b507ac97d53777aba for an alternative implementation).
For Java 9+, you could do something like my net.ltgt.errorprone-javacplugin plugin.

Jonathan Bluett-Duncan

unread,
Jun 19, 2018, 6:15:16 PM6/19/18
to error-pro...@googlegroups.com
Hi Thomas,

Wow, thank you very much for your help! I've been working again on my Gradle plugin for Refaster tonight, and I've had some success with following your explanation below to improve it, but I'm currently stuck getting the plugin to recognise Refaster's "--out" option.

To explain what I mean, if one clones https://github.com/jbduncan/jupiter-collection-testers, switches to branch "refaster-plugin-improvements" and runs "gradlew clean compileRefasterTemplate --full-stacktrace" from the command-line (where "compileRefasterTemplate" is a custom task that my plugin introduces), then the following exception log is produced: https://gist.github.com/jbduncan/b6a05aeaf6ec06e3bd47cd7d49415b9c

I thus wonder if you have any further thoughts that might allow me to get unstuck?

Cheers,
Jonathan

--
Googlers: This an external list. Please be careful when posting.
---
You received this message because you are subscribed to a topic in the Google Groups "error-prone-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/error-prone-discuss/Ha2gYHER9ik/unsubscribe.
To unsubscribe from this group and all its topics, send an email to error-prone-dis...@googlegroups.com.
Visit this group at https://groups.google.com/group/error-prone-discuss.
To view this discussion on the web visit https://groups.google.com/d/msgid/error-prone-discuss/aae13ba5-e8d4-4df0-9de9-a74977148778%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thomas Broyer

unread,
Jun 20, 2018, 2:02:19 AM6/20/18
to error-pro...@googlegroups.com
Arguments to javac plugins are passed space-separated in the same argument as the -Xplugin (and cannot contain spaces themselves, as javac simply splits the string, without caring about things like quotes)

Jonathan Bluett-Duncan

unread,
Jun 21, 2018, 3:38:07 PM6/21/18
to error-pro...@googlegroups.com
Hi Thomas,

On Wed, 20 Jun 2018 at 07:02, Thomas Broyer <t.br...@gmail.com> wrote:
Arguments to javac plugins are passed space-separated in the same argument as the -Xplugin (and cannot contain spaces themselves, as javac simply splits the string, without caring about things like quotes)

Oof, that's problematic!

I'm trying to get my plugin to pass -Xplugin arguments to Refaster like -Xplugin --out C:\path\with\space\like\IntelliJ Projects\junit5-collection-testers\build\refaster\templates\src\refaster\java\com\github\jbduncan\collect\testing\CollectionIsEmpty.refaster, which currently doesn't work because, accordingly as you've stated above, the arguments get split on the space within "IntelliJ Projects".

Do you know of any workarounds? Alteratively, do you have any other thoughts that might allow me to move forward with this?

Cheers,
Jonathan
 

Jonathan Bluett-Duncan

unread,
Jun 21, 2018, 5:58:46 PM6/21/18
to error-pro...@googlegroups.com
Wait. never mind, I found a workaround by telling my Gradle plugin to first use -Xplugin --out /path/to/tmp/file/without/space/CollectionIsEmpty.refaster and then moving it to the correct location as a doLast action of the corresponding Gradle task.

So feel free to ignore my last email! 🙇

Cheers,
Jonathan

Jonathan Bluett-Duncan

unread,
Jul 4, 2018, 4:56:30 PM7/4/18
to error-pro...@googlegroups.com
Ah, actually, tackling it some more, it looks like it's not really easy at all to generate a temp file which
  1. is guaranteed to not have any spaces in its path (Files.createTempFile seems to work on my machine running Windows 7, but I don't know if it would work on machines where e.g. the current user has a space in their name, or if it would work on Windows 10 or Unix-based OSs), and
  2. which has a reproducible name and path, which is apparently necessary for it to be an input for a Gradle task that supports UP-TO-DATE checks.
My current workaround (if you'd call it that), as of yet unpublished, is to throw a GradleException if one attempts to compile a Refaster template like /path/with space/CollectionIsEmpty.java.

If any of you have any thoughts that might allow my plugin to let users pass in Refaster templates with spaces in their names, I'd love to hear them. :)

Cheers,
Jonathan

Reply all
Reply to author
Forward
0 new messages