lovubuntu / checker-framework

Automatically exported from code.google.com/p/checker-framework
0 stars 0 forks source link

Qualifier inference for nested ternary expressions #331

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
# What steps will reproduce the problem?

Run the nullness checker over the following program:

===
import org.checkerframework.checker.nullness.qual.*;
import org.checkerframework.checker.initialization.qual.*;

import java.util.*;

class Test {
  List<String> m(@Nullable String s1, @Nullable String s2) {
    List<String> rows = new ArrayList<>();
    {
      // OK:
      @Initialized @NonNull String string = s1 == null ? "" : (s2 == null ? "" : s2);
      rows.add(string);
    }
    {
      // ERROR:
      String string = s1 == null ? "" : (s2 == null ? "" : s2);
      rows.add(string);
    }
    return rows;
  }
}
===

# What is the expected output? What do you see instead?

I expect the analysis to succeed. Instead:

$ ~/jsr308/checker-framework-1.8.1/checker/bin/javac -processor 
org.checkerframework.checker.nullness.NullnessChecker -cp 
~/jsr308/checker-framework-1.8.1/checker/dist/checker-qual.jar Test.java
Test.java:17: error: [argument.type.incompatible] incompatible types in 
argument.
      rows.add(string);
               ^
  found   : @UnknownInitialization @Nullable String
  required: @Initialized @NonNull String

# What version of the product are you using? On what operating system?

v1.8.1

#Please provide any additional information below.

This only seems to affect nested ternary expressions.

Original issue reported on code.google.com by cus...@google.com on 17 May 2014 at 8:19

GoogleCodeExporter commented 9 years ago
Thanks for the bug report!

This example is a little bit simpler and has the same issue:

  List<Object> foo(boolean b) {
    List<Object> res = new ArrayList<>();
    Object o = b ? "" : (b ? "" : "");
    res.add(o);
    return res;
  }

It looks like there is a problem in CFG handling in this case.

Original comment by wdi...@gmail.com on 19 May 2014 at 6:48

GoogleCodeExporter commented 9 years ago

Original comment by michael.ernst@gmail.com on 25 May 2014 at 4:23

GoogleCodeExporter commented 9 years ago

Original comment by michael.ernst@gmail.com on 29 May 2014 at 4:04

GoogleCodeExporter commented 9 years ago

Original comment by jtha...@cs.washington.edu on 1 Jul 2014 at 10:22

GoogleCodeExporter commented 9 years ago

Original comment by jtha...@cs.washington.edu on 1 Jul 2014 at 10:22