Skip to content

org.openrewrite.java.migrate.util.MigrateCollectionsSingletonList should not convert known null #571

@blipper

Description

@blipper

What is the smallest, simplest way to reproduce the problem?

import java.util.Collections;

class A {
    void foo( {
     Collections.singletonList(null);
    }
}

What did you expect to see?

import java.util.Collections;

class A {
    void foo( {
     Collections.singletonList(null);
    }
}

What did you see instead?

class A {
    void foo( {
     List.of(null);
    }
}

Really this should be any provably null or if conservative only provably non-null.

This is a problem because singleList allows null element.
https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/List.html#of(E)
https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Collections.html#singletonList(T)

Are you interested in contributing a fix to OpenRewrite?

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions