为什么 Intellij Idea 不能正确地 delombok builder

Why Intellij Idea does not delombok builder correctly

我在 Intellij Idea 中遇到了 lombok 生成的构建器。显示我可以创建的问题的最小示例是

import java.io.IOException;
import lombok.AllArgsConstructor;
import lombok.Builder;

class Base { }

@Builder
@AllArgsConstructor
class Scratch extends Base {
    String attr;
    String attr2;

    public Scratch(Base b) throws IOException {
        throw new IOException();
    }

    public static void main(String[] args) {
        Scratch.builder().attr("1").attr2("2").build(); // Idea shows an error here
    }
}

Idea 在调用 build() 的行中显示错误并抱怨 Unhandled exception: java.io.IOException。但是代码可以从命令行编译和运行。 idea 和命令行中的 java 编译器与 java 8 的版本相同。当我尝试 "delombok" idea 中的代码时,我看到生成的 idea ScratchBuilder.build 是:

    public Scratch build() throws IOException {
        return new Scratch(attr, attr2);
    }

奇怪,虽然生成的全参数构造函数没有抛出任何东西,但build方法中有一个throws。如果我简单地从构建方法中删除 throws 子句,Idea 就会停止抱怨。

idea为什么认为build方法中应该有一个throws?

题中描述的问题是lombok-intellij-plugin的bug。我在 github 中报告了错误,Michail Plushnikov 接受了错误报告并更正了 lombok-intellij-plugin 中的错误。详情见https://github.com/mplushnikov/lombok-intellij-plugin/issues/740