Skip to content

[false-negative]ToStringReturnsNull can not detect the case that return a variable which is initially null, and there is no subsequent re-assignment. #1660

@wuchiuwong

Description

@wuchiuwong

Description of the problem / feature request:

ToStringReturnsNull can not detect the case that return a variable which is initially null, and there is no subsequent re-assignment.
This rule is implemented in error_prone_core-2.3.4-sources.jar!\com\google\errorprone\bugpatterns\ToStringReturnsNull.java,
and use node.getExpression().getKind() == NULL_LITERAL; to check whether null is returned,
Therefore, it will not detect those return a variable which may be null

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

@Override
public String toString() {
    String result = null;
	try {
		result = new ObjectMapper().defaultPrettyPrintingWriter().writeValueAsString(this);
	} catch (IOException e) {
		logger.warn(e,e);
	}
    return result;
}

What version of Error Prone are you using?

2.3.4

Have you found anything relevant by searching the web?

no

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions