Java Intellij14,Lambda表达式错误,显示错误,尽管没有编译器错误

Java Intellij14,Lambda表达式错误,显示错误,尽管没有编译器错误,java,intellij-idea,Java,Intellij Idea,当Intellij 14中的lambdas用于引发异常的接口时,Intellij会错误地将其突出显示为错误。 我一直试图以更简单的形式重现错误,但这并不容易。我现在被迫用匿名内部类替换lambda 好的,我在这里能够找出根本问题,并且能够重现一个工作示例: // Works fine public static void exampleOne() throws IOException { methodOne(); methodT

当Intellij 14中的lambdas用于引发异常的接口时,Intellij会错误地将其突出显示为错误。

我一直试图以更简单的形式重现错误,但这并不容易。我现在被迫用匿名内部类替换lambda

好的,我在这里能够找出根本问题,并且能够重现一个工作示例:

    // Works fine
    public static void exampleOne() throws IOException {

            methodOne();

            methodTwo(() -> {

            });

    }

    // Works fine
    public static void exampleTwo() throws IOException {

            // IOException bubbles up here, which is thrown by the method signature
            methodTwo(() -> {
                    methodOne(); // throws IOException
            });
    }

    // Works fine
    public static void exampleThree() throws IOException {

            methodTwo(() -> {
                    methodOne();

                    methodTwo(() -> {

                    });
            });
    }

    // !!!!!! Error !!!!!!!!
    public static void exampleFour() throws IOException {

            methodTwo(() -> {
                    methodOne();

                    methodThree(() -> {

                    });
            });


            // Error here!

            // It appears as if methodOne throws IOException, which should bubble up, and then methodThree call does not throw anything but Intellij gets confused
            // If we look at exampleThree then we can see that a call to the same as the one we called first methodTwo does not yield any problems.

            // This error does not exist in Intellij 13 and compiles fine with Java.

            // Error type cannot be ignored in Intellij which is a major issue!
    }

    // Works fine
    public static void exampleFourAnonymous() throws IOException {

            methodTwo(new Callable<IOException>() {
                    @Override
                    public void call() throws IOException {
                            methodOne();

                            methodThree(() -> {

                            });
                    }
            });
    }

    public static interface Callable<E extends Throwable> {
            void call() throws E;
    }

    public static void methodOne() throws IOException {
    }

    public static <E extends Throwable> void methodTwo(Callable<E> lambda) throws E {
            lambda.call();
    }

    public static <E extends Throwable> void methodThree(Callable<E> lambda) throws E {
            lambda.call();
    }
//很好用
public static void exampleOne()引发IOException{
方法一();
方法二(()->{
});
}
//很好
public static void exampleTwo()引发IOException{
//IOException在这里冒泡,由方法签名引发
方法二(()->{
methodOne();//引发IOException
});
}
//很好
public static void exampletree()引发IOException{
方法二(()->{
方法一();
方法二(()->{
});
});
}
// !!!!!! 错误!!!!!!!!
public static void examplefur()引发IOException{
方法二(()->{
方法一();
方法三(()->{
});
});
//这里出错了!
//看起来好像methodOne抛出IOException,它应该会冒泡,然后methodThree调用不会抛出任何东西,但Intellij会感到困惑
//如果我们看一下示例三,那么我们可以看到调用与我们调用的第一个methodTwo相同的方法不会产生任何问题。
//Intellij 13中不存在此错误,可以使用Java进行良好编译。
//Intellij中的错误类型不能忽略,这是一个主要问题!
}
//很好
public static void exampleFourAnonymous()引发IOException{
方法二(新的可调用(){
@凌驾
public void call()引发IOException{
方法一();
方法三(()->{
});
}
});
}
公共静态接口可调用{
void call()抛出E;
}
公共静态void methodOne()引发IOException{
}
publicstaticvoidmethod2(可调用lambda)抛出E{
lambda.call();
}
公共静态无效方法三(可调用lambda)抛出E{
lambda.call();
}
Intellij 13中不存在此错误


这是有效的错误消息吗?

现已修复:youtrack.jetbrains.com/issue/IDEA-134808

我可以确认此行为。可能您应该将此错误提交给IntelliJ bugtracker。这似乎是离题的,因为这不是一个问题。在NetBeans中不会发生。IntelliJ似乎没有在methodThree参数的开头对IOException施加限制。这种预期的与派生的类型行为在java中不断被重新设计。提交错误报告以解决此不兼容问题。YouTrack具有“还原密码”功能。请将此作为错误进行归档。StackOverlow不是问题追踪者。感谢您在@momo提交问题!