Intellij 14, Lambda Buggy Expressions, Shows Error Despite No Compiler Errors

When using lambdas in Intellij 14 for interfaces that throw an exception, Intellij incorrectly highlights them as errors.

I am trying to reproduce the error in a simpler form, but it has been tricky. I am now forced to replace my lambdas with anonymous inner classes.

Ok, I was able to figure out the cause of the problem here and was able to reproduce a working example:

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

      

This error does not exist in Intellij 13.

Is this a valid error message?

+3


source to share


1 answer


Fixed now: youtrack.jetbrains.com/issue/IDEA-134808



0


source







All Articles