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

Checker allows Map.entry to take nulls. #6136

Closed
agentgt opened this issue Aug 17, 2023 · 8 comments
Closed

Checker allows Map.entry to take nulls. #6136

agentgt opened this issue Aug 17, 2023 · 8 comments

Comments

@agentgt
Copy link

agentgt commented Aug 17, 2023

Checker seems to have no problem accepting:

Map.entry(null, null);

I figured it was because it was not annotated correctly so I tried a astub file of:

//Map.astub
package java.util;

import org.checkerframework.checker.nullness.qual.NonNull;

public interface Map<K, V> {
  // n.b. the parameters here are not from the interface
  public static <K, V> Entry<K, V> entry(@NonNull K k, @NonNull V v);
  // I also tried because DefaultQualifier cannot be put on stubs
  public static <@NonNull K, @NonNull V> Entry<@NonNull K, @NonNull V> entry(@NonNull K k, @NonNull V v);
}
@mernst
Copy link
Member

mernst commented Aug 17, 2023

With the stub file, is your problem resolved?

@agentgt
Copy link
Author

agentgt commented Aug 17, 2023

No which is bizarre because I have other stub files. I tried testing that the stub file was being read by making Map.entry return @Nullable and that failed correctly (correctly by it did what it was told... obviously map.entry should not return nullable ... for others).

@smillst
Copy link
Member

smillst commented Aug 17, 2023

The following gives the expected warnings:

$ cat MapEntryNull.java
import java.util.Map;
import org.checkerframework.checker.nullness.qual.NonNull;

public class MapEntryNull {
  void m(){
    Map.entry(null,null);
  }
}
$ cat /Users/smillst/jsr308/testcases/src/Map.astub
package java.util;

 import org.checkerframework.checker.nullness.qual.NonNull;

 public interface Map<K, V> {
   public static <K, V> Entry<K, V> entry(@NonNull K k, @NonNull V v);
 }
$ javacheck -processor nullness MapEntryNull.java -Astubs=/Users/smillst/jsr308/testcases/src/Map.astub
MapEntryNull.java:6: error: [argument] incompatible argument for parameter k of Map.entry.
    Map.entry(null,null);
              ^
  found   : null (NullType)
  required: @Initialized @NonNull Object
MapEntryNull.java:6: error: [argument] incompatible argument for parameter v of Map.entry.
    Map.entry(null,null);
                   ^
  found   : null (NullType)
  required: @Initialized @NonNull Object
2 errors

@agentgt
Copy link
Author

agentgt commented Aug 17, 2023

Here is my setup in Maven. I am using JDK 17.

    <profile>
      <id>checkerframework</id>
      <properties>
        <checkerframework.version>3.37.0</checkerframework.version>
      </properties>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
              <fork>true</fork>
              <compilerArgs combine.children="append">
                <arg>-Astubs=${parent.root}/etc/eea/checker</arg>
                <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
                <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
                <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
                <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
                <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
                <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
                <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
                <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
                <arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
              </compilerArgs>
              <annotationProcessorPaths>
                <path>
                  <groupId>org.checkerframework</groupId>
                  <artifactId>checker</artifactId>
                  <version>${checkerframework.version}</version>
                </path>
              </annotationProcessorPaths>
              <annotationProcessors>
                <!-- Add all the checkers you want to enable here -->
                <annotationProcessor>org.checkerframework.checker.nullness.NullnessChecker</annotationProcessor>
              </annotationProcessors>
            </configuration>
          </plugin>
        </plugins>
      </build>
      <dependencies>
        <dependency>
          <groupId>org.checkerframework</groupId>
          <artifactId>checker</artifactId>
          <version>${checkerframework.version}</version>
        </dependency>
        <dependency>
          <groupId>org.checkerframework</groupId>
          <artifactId>checker-qual</artifactId>
          <version>${checkerframework.version}</version>
        </dependency>
      </dependencies>
    </profile>

I know checker works because it failed on other things and if change my Map.astub file to return @Nullable it fails.

Is my configuration wrong?

@agentgt
Copy link
Author

agentgt commented Aug 17, 2023

Edit ok I copied and pasted @smillst stub and it works for me.

I have know idea why as mine was basically the same.

@agentgt
Copy link
Author

agentgt commented Aug 17, 2023

We can probably close this. There must have been a strange cache issue. I still cannot understand how it could have possibly happened but I do have the Maven cache extension installed (but disabled).

@agentgt agentgt closed this as completed Aug 17, 2023
@agentgt
Copy link
Author

agentgt commented Aug 17, 2023

My apologies @mernst and @smillst on the incorrect bug. However I do think we should update typetools/jdk with the correct annotation right?

@smillst
Copy link
Member

smillst commented Aug 17, 2023

Thanks for reporting this and for the jdk pull request!

agentgt added a commit to jstachio/jstachio that referenced this issue Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants