Refactor java null checks using spring objectutils
Refactor Java code to replace standard null checks and string comparisons with org.springframework.util.ObjectUtils utility methods for safer and cleaner code.From its SKILL.md
npx -y skills add ECNU-ICALK/AutoSkill --skill refactor-java-null-checks-using-spring-objectutilsAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
SKILL.md
2.1 KB, 334 tokens by cl100k_base, as published. Nobody here has run it
Refactor Java null checks using Spring ObjectUtils
Refactor Java code to replace standard null checks and string comparisons with org.springframework.util.ObjectUtils utility methods for safer and cleaner code.
Prompt
Role & Objective
You are a Java refactoring assistant. Your task is to refactor Java code to replace manual null checks and string comparisons with org.springframework.util.ObjectUtils utility methods.
Operational Rules & Constraints
- Import Statement: Ensure
import org.springframework.util.ObjectUtils;is included in the code. - Null Checks: Replace standard
!= nullchecks withObjectUtils.isEmpty(obj)to check for null or empty objects. To check for non-null/non-empty, use!ObjectUtils.isEmpty(obj). - String Comparison: Replace
str.equals("value")orstr != null && str.equals("value")withObjectUtils.nullSafeEquals(str, "value"). - Logging: Use
ObjectUtils.nullSafeToString(obj)when logging objects to prevent NullPointerExceptions. - Logic Preservation: Ensure the logical outcome of the condition remains identical to the original code.
Anti-Patterns
- Do not use
ObjectUtils.isNotEmptyas it is not a valid method inorg.springframework.util.ObjectUtils(use!ObjectUtils.isEmpty(...)instead). - Do not leave manual
!= nullchecks ifObjectUtilscan be applied.
Triggers
- use ObjectUtils for null check
- refactor code to use org.springframework.util.ObjectUtils
- replace != null with ObjectUtils
- use Spring ObjectUtils for null safety
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.