Skip to content

Commit

Permalink
[pr #2637] recent versions of ecj double-close the classfile stream, …
Browse files Browse the repository at this point in the history
…causing corrupt classfiles

Would crash with java.lang.ClassFormatError: Extra bytes at the end of class file de/lomboktest/Application
Fixes mplushnikov/lombok-intellij-plugin#969

figuring out the problem was the hard work - credits to @Rawi01 for discovering this
  • Loading branch information
rzwitserloot committed Dec 4, 2020
1 parent da2c793 commit b586c54
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/core/lombok/core/PostCompiler.java
Expand Up @@ -28,6 +28,7 @@
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*/};
Expand Down Expand Up @@ -67,8 +68,17 @@ private static synchronized void init(DiagnosticsReceiver diagnostics) {

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;
Expand Down

0 comments on commit b586c54

Please sign in to comment.