mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-13 20:15:09 +00:00
[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
This commit is contained in:
1 file changed
+10
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user