Intellij 14,Lambda表达式错误,尽管没有编译器错误,但仍显示错误

时间:2014-12-25 11:47:08

标签: java intellij-idea

在Intellij 14中使用lambda用于抛出异常的接口时,Intellij 错误地将它们突出显示为错误。

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

好的,我能够在这里找出根本问题,并且能够重现一个有效的例子:

    // 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();
    }

Intellij 13中不存在此错误。

这是有效的错误消息吗?

1 个答案:

答案 0 :(得分:0)

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