Skip to content

False positive RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE for class.getResourceAsStream #1250

@Remblej

Description

@Remblej

This code shows warning RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE

        try (InputStream stream = MyClass.class.getResourceAsStream(resourceName)) {
            if (stream != null) {
                // code
            }
        } // <- warning points here

Warning message: "This method contains a redundant check of a known non-null value against the constant null."
getResourceAsStream is not null safe, as javadoc says:

@return  A {@link java.io.InputStream} object; {@code null} if no
     *          resource with this name is found, the resource is in a package
     *          that is not {@linkplain Module#isOpen(String, Module) open} to at
     *          least the caller module, or access to the resource is denied
     *          by the security manager.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions