Skip to content

Incorrect error when using @OrderNonDet collection in String concatenation #194

@jwaataja

Description

@jwaataja

When using an @OrderNonDet collection as a String in String concatenation, it should be treated as a @NonDet String because the order of the contents are not known. However, the checker tries to give the String type @OrderNonDet, which generates the warning that @OrderNonDet can't be written on such a type (String). This is shown in this class

import org.checkerframework.checker.determinism.qual.*;
import java.util.*;

public class C {
    public void f(@OrderNonDet Set<@Det String> set) {
        String s = "literal" + set;
    }
}
.java:6: error: [ordernondet.on.noncollection.and.nonarray] @OrderNonDet annotation is invalid for non-collections and non-arrays
        String s = "literal" + set;
                             ^

Either set's toString return type should be used instead of set's type here for the String, or primitive operations like addition should change @OrderNonDet to @NonDet automatically, instead of issuing an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions