Skip to content

[Question] use checkstyle to avoid ==null check #5921

@eye-gu

Description

@eye-gu

Question

I have seen many recently pr change ==null to Objects.isNull. Can we consider using checkstyle to avoid? I tried it locally and found that there are quite a few areas that need to be modified.

checkstyle config as follows:

<module name="RegexpSinglelineJava">
  <property name="format" value="==\s*null"/>
  <property name="message" value="Use Objects.isNull() instead of == null"/>
</module>

<module name="RegexpSinglelineJava">
  <property name="format" value="null\s*=="/>
  <property name="message" value="Use Objects.isNull() instead of null =="/>
</module>

<module name="RegexpSinglelineJava">
  <property name="format" value="!=\s*null"/>
  <property name="message" value="Use Objects.nonNull() instead of != null"/>
</module>

<module name="RegexpSinglelineJava">
  <property name="format" value="null\s*!="/>
  <property name="message" value="Use Objects.nonNull() instead of null !="/>
</module>

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions