GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — assignment.type.incompatible only with explicit "extends @Nullable Object" on type parameter · Issue #2995 · typetools/checker-framework

assignment.type.incompatible only with explicit "extends @Nullable Object" on type parameter #2995

New issue
Copy link
New issue
Copy link
Closed
#8303
Closed
assignment.type.incompatible only with explicit "extends @Nullable Object" on type parameter#2995
#8303
Copy link
Labels
False Positive (false warning or imprecision)bug

Description

@cpovirk
cpovirk
opened on Dec 17, 2019
Issue body actions

I could be confused, but: I would expect class Map<K> and class Map<K extends @Nullable Object> to be equivalent. It appears that they're not. Here's some code that uses the longer version:

$ cat Map.java 
import org.checkerframework.checker.nullness.qual.Nullable;

interface Set<E> {}

class Map<K extends @Nullable Object> {
  Set<K> keySet = new KeySet();

  class KeySet implements Set<K> {}
}

$ checker/bin/javac -processor org.checkerframework.checker.nullness.NullnessChecker Map.java
Map.java:6: error: [assignment.type.incompatible] incompatible types in assignment.
  Set<K> keySet = new KeySet();
                  ^
  found   : @Initialized @NonNull Map<K extends @Initialized @NonNull Object>.@Initialized @NonNull KeySet
  required: @Initialized @NonNull Set<K extends @Initialized @Nullable Object>
1 error

However, if I tweak the class declaration to the "equivalent" shorter version, then the file compiles successfully. That's the behavior I would have expected in either case.

If I suppress the error, the .class files that I get for the long version is almost identical to that for the short version, according to javap -v. The only difference appears to be in the order of the RuntimeVisibleTypeAnnotations.

Source file and -version -verbose -AprintAllQualifiers output attached.

Activity

  1. cpovirk commented on Dec 19, 2019

    @cpovirk
    cpovirk
    on Dec 19, 2019
    ContributorAuthor
    More actions

    This turns out to affect implementations of the JDK's Map type, since it's defined with explicit <K extends @Nullable Object, V extends @Nullable Object>:

    checker-framework/checker/jdk/nullness/src/java/util/Map.java

    Line 139 in 64f05c4

    public interface Map<K extends @Nullable Object, V extends @Nullable Object> {

    (similarly in typetools/jdk)

    Map appears to be one of only 3 classes under checker/jdk/nullness that uses the long version of such bounds. (The other 2 are Map.Entry and HashMap.) Would it be helpful for me to send a PR to change them to plain <K, V> as a workaround until this bug is fixed (assuming that it is a bug)?

  2. smillst commented on Dec 19, 2019

    @smillst
    smillst
    on Dec 19, 2019
    Member
    More actions

    Yes, this is a bug; your test case should not issue any warnings. This may be related to #2926.

    Would it be helpful for me to send a PR to change them to plain <K, V> as a workaround until this bug is fixed?

    I think that would be helpful. Thanks!

  3. smillst
    added
    bug
    False Positive (false warning or imprecision)
    on Dec 19, 2019
  4. cpovirk
    added 2 commits that reference this issue on Dec 19, 2019

    Remove explicit "extends @nullable Object."

    dd709b4

    Remove explicit "extends @nullable Object."

    e2e1190
  5. smillst
    added 2 commits that reference this issue on Dec 20, 2019

    Remove explicit "extends @nullable Object." (#3007)

    15f227b

    Remove explicit "extends @nullable Object." (#26)

    05f1d06
  6. cpovirk
    added a commit that references this issue on Apr 24, 2020

    Annotate for the Checker Framework -- sort of!

    f788577
  7. smillst
    closed this as completedin #8303on Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    False Positive (false warning or imprecision)bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.