Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regression: Problems with stream / lambda #1011

Closed
maggu2810 opened this issue Jan 17, 2017 · 2 comments
Closed

regression: Problems with stream / lambda #1011

maggu2810 opened this issue Jan 17, 2017 · 2 comments

Comments

@maggu2810
Copy link

maggu2810 commented Jan 17, 2017

Previously reported here: https://groups.google.com/d/msg/checker-framework-discuss/v9k0y6cRmyE/2GfHd_iGCQAJ

Hi,

I would like to use the most recent version of the Checker Framework in my project.
After the bump an error has been thrown.
The code looks good to me, so I assume it is / could be a regression in the Checker Framework.

The framework does not complain using 2.1.5 and 2.1.6
After switching to 2.1.7 it complains:

Demo.java:20: error: [lambda.param.type.incompatible] incompatible parameter types in lambda expression.
                .map(key -> String.format("%s=%s", key, timeTemperatures.get(key))).collect(Collectors.joining(",")));
                     ^
  found   : @KeyFor("this.timeTemperatures") DayOfWeek
  required: @KeyFor("[error for expression: this.timeTemperatures error: this.timeTemperatures: findPackage threw an exception when looking up package this: null]") DayOfWeek
1 error

error: [[all, keyfor]:lambda.param.type.incompatible] incompatible parameter types in lambda expression.

After using

@SuppressWarnings(value = { "lambda.param.type.incompatible" })

for the respective function it complains about:

Demo.java:21: error: [expression.unparsable.type.invalid] Expression annotation invalid: [error for expression: this.timeTemperatures error: this.timeTemperatures: findPackage threw an exception when looking up package this: null]
                .map(key -> String.format("%s=%s", key, timeTemperatures.get(key))).collect(Collectors.joining(",")));
                     ^
1 error

After using

@SuppressWarnings(value = { "lambda.param.type.incompatible", "expression.unparsable.type.invalid" })

for the respective function it does not complain anymore, but I don't think suppress warnings is the correct way to solve it (perhaps only a temporary workaround).

Here the code that raises the error:

package tmp;

import java.math.BigDecimal;
import java.time.DayOfWeek;
import java.time.LocalTime;
import java.util.SortedMap;
import java.util.stream.Collectors;

public class Demo {
    protected final SortedMap<DayOfWeek, SortedMap<LocalTime, BigDecimal>> timeTemperatures;

    public Demo(final SortedMap<DayOfWeek, SortedMap<LocalTime, BigDecimal>> timeTemperatures) {
        this.timeTemperatures = timeTemperatures;
    }

    @Override
    public String toString() {
        return String.format("time=[%s]", timeTemperatures.keySet().stream()
                .map(key -> String.format("%s=%s", key, timeTemperatures.get(key))).collect(Collectors.joining(",")));
    }

}

I receive another error using 2.1.7 and a static method

package tmp;

import java.math.BigDecimal;
import java.time.DayOfWeek;
import java.time.LocalTime;
import java.util.SortedMap;
import java.util.stream.Collectors;

public class Demo {
    public String test(final SortedMap<DayOfWeek, SortedMap<LocalTime, BigDecimal>> timeTemperatures) {
        return String.format("time=[%s]", timeTemperatures.keySet().stream()
                .map(key -> String.format("%s=%s", key, timeTemperatures.get(key))).collect(Collectors.joining(",")));
    }
}
javac -Xbootclasspath/p:/home/rathgeb/.m2/repository/org/checkerframework/jdk8/2.1.7/jdk8-2.1.7.jar -cp /home/rathgeb/.m2/repository/org/checkerframework/checker/2.1.7/checker-2.1.7.jar -processor org.checkerframework.checker.nullness.NullnessChecker -AprintErrorStack Demo.java 
error: SourceChecker.typeProcess: unexpected Throwable (StackOverflowError) while processing Demo.java
  Compilation unit: Demo.java
  Exception: java.lang.StackOverflowError; Stack trace: com.sun.tools.javac.code.Scope.dup(Scope.java:123)
  com.sun.tools.javac.comp.Attr.lambdaEnv(Attr.java:2666)
  com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2305)
  com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
  com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
  com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2435)
  com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
  com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
  com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2435)
  com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
  com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
  com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2435)
  com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
  com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
  com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2435)
  com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
  com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
  com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2435)
  com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
  com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
  com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2435)
  com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
  com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
  com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2435)
  com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
  com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
  com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2435)
...
  com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
  com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
  com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2435)
  com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
  com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
  com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2435)
  com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
1 error

@wmdietlGC
Copy link
Contributor

The StackOverflowError in the second part of the message is probably fixed by #1027

The issues with KeyFor/expression annotation parsing still need fixing.

@mernst mernst removed the crash label Feb 15, 2017
@smillst
Copy link
Member

smillst commented Feb 24, 2017

I can't reproduce these errors any more. I believe they were fixed by two recent changes:
the SOE was fixed by: aff0922 and the "expression.unparsable.type.invalid" was fixed by 8ce6ee5.

@smillst smillst closed this as completed Feb 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants