aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReinier Zwitserloot <r.zwitserloot@projectlombok.org>2020-12-04 04:17:05 +0100
committerReinier Zwitserloot <r.zwitserloot@projectlombok.org>2020-12-04 04:17:05 +0100
commitb586c543cdf9338e112ab8a6668262ab350742e4 (patch)
treee9bb004b1c4ce7f789d8a5e83545f35d340fa97b
parentda2c793083efddc9d73342622204b83591aa10a8 (diff)
downloadlombok-b586c543cdf9338e112ab8a6668262ab350742e4.tar.gz
lombok-b586c543cdf9338e112ab8a6668262ab350742e4.tar.bz2
lombok-b586c543cdf9338e112ab8a6668262ab350742e4.zip
[pr #2637] recent versions of ecj double-close the classfile stream, causing corrupt classfiles
Would crash with java.lang.ClassFormatError: Extra bytes at the end of class file de/lomboktest/Application Fixes https://github.com/mplushnikov/lombok-intellij-plugin/issues/969 figuring out the problem was the hard work - credits to @Rawi01 for discovering this
-rw-r--r--src/core/lombok/core/PostCompiler.java10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/core/lombok/core/PostCompiler.java b/src/core/lombok/core/PostCompiler.java
index 72f4b3a2..122bb268 100644
--- a/src/core/lombok/core/PostCompiler.java
+++ b/src/core/lombok/core/PostCompiler.java
@@ -28,6 +28,7 @@ import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Collections;
import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
public final class PostCompiler {
private PostCompiler() {/* prevent instantiation*/};
@@ -67,8 +68,17 @@ public final class PostCompiler {
public static OutputStream wrapOutputStream(final OutputStream originalStream, final String fileName, final DiagnosticsReceiver diagnostics) throws IOException {
if (System.getProperty("lombok.disablePostCompiler", null) != null) return originalStream;
+
+ // close() can be called more than once and should be idempotent, therefore, ensure we never transform more than once.
+ final AtomicBoolean closed = new AtomicBoolean();
+
return new ByteArrayOutputStream() {
@Override public void close() throws IOException {
+ if (closed.getAndSet(true)) {
+ originalStream.close();
+ return;
+ }
+
// no need to call super
byte[] original = toByteArray();
byte[] copy = null;