google / j2cl

Java to Closure JavaScript transpiler
Apache License 2.0
1.23k stars 144 forks source link

GwtIncompatibleStripper adds an extra newline to files with no `@GwtIncompatible` annotation #152

Closed niloc132 closed 2 years ago

niloc132 commented 2 years ago

Describe the bug .java files with no @GwtIncompatible annotation have an extra newline appended to the end after they are processed by the GwtIncompatibleStripper. I have not validated if files which do contain a @GwtIncompatible annotation are also affected in this way.

To Reproduce Method one, in J2CL itself, using Bazel to build:

Method two, running the preprocessor directly on a single file, without Bazel:

Bazel version Please include version of Bazel that you are running J2CL with:

[colin@runes j2cl ((d3835de...))]$ bazel version
Bazelisk version: v1.7.4
Build label: 5.1.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Thu Mar 24 14:02:30 2022 (1648130550)
Build timestamp: 1648130550
Build timestamp as int: 1648130550

Expected behavior A clear and concise description of what you expected to happen. Files that require no changes by the preprocessor should have no changes made to them.

gkdn commented 2 years ago

Thanks for the detailed report. Do you already have a patch?

I'm little bit surprised. We have unit tests covering GwtIncompatibleStripperTest behavior. Are we missing something there?

niloc132 commented 2 years ago

I haven't dug in to the code to see where it is coming from except to say that I can't see where it is coming from :). I definitely agree that the tests look like they should cover this case, so my hunch is that it is somehow IO related - the tests appear to validate the strings, and so perhaps OutputUtils is doing something it shouldn't? I'm afraid that's as far as I've gotten.

gkdn commented 2 years ago

I have a theory. Will send a quick lazy fix without trying to repro...

gkdn commented 2 years ago

(I'm pretty confident that this should fix it but pls re-open if it is not fixed)