Skip to content

Commit

Permalink
[type:feature] use checkstyle to avoid ==null check (apache#5927)
Browse files Browse the repository at this point in the history
  • Loading branch information
eye-gu authored Feb 8, 2025
1 parent d01c5ec commit 60676c1
Show file tree
Hide file tree
Showing 200 changed files with 380 additions and 292 deletions.
24 changes: 24 additions & 0 deletions script/shenyu_checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -268,5 +268,29 @@
<!-- Filters -->
<module name="SuppressionCommentFilter"/>
<module name="SuppressWithNearbyCommentFilter"/>

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

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

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

<module name="RegexpSinglelineJava">
<property name="format" value="null\s*!="/>
<property name="message" value="Use Objects.nonNull() instead of null !="/>
<property name="ignoreComments" value="true"/>
</module>
</module>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;
Expand Down Expand Up @@ -130,7 +131,7 @@ private <T> void onCommonChanged(final String configKeyPrefix, final List<T> cha
final List<String> configDataNames = this.getConfigDataNames(configKeyPrefix);
changedList.forEach(changedData -> publishConfig(configKeyPrefix + mapperToKey.apply(changedData), changedData));

if (configDataNames != null && configDataNames.size() > changedList.size()) {
if (Objects.nonNull(configDataNames) && configDataNames.size() > changedList.size()) {
configDataNames.removeAll(changeNames);
configDataNames.forEach(this::delConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.slf4j.LoggerFactory;

import java.util.Date;
import java.util.Objects;
import java.util.Optional;

/**
Expand Down Expand Up @@ -65,7 +66,7 @@ public String getItemValue(final String key) {
apolloConfig.getClusterName(),
apolloConfig.getNamespace(),
key);
if (openItemDTO == null) {
if (Objects.isNull(openItemDTO)) {
return null;
}
if (openItemDTO.getKey().equals("timeout")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Objects;

/**
* Use polaris to push data changes.
*/
Expand Down Expand Up @@ -61,7 +63,7 @@ public void doPublishConfig(final String dataId, final Object data) {
polarisProperties.getFileGroup(),
dataId);
if (isReleased(metadata)) {
configFilePublishService.updateConfigFile(metadata, data == null ? "" : GsonUtils.getInstance().toJson(data));
configFilePublishService.updateConfigFile(metadata, Objects.isNull(data) ? "" : GsonUtils.getInstance().toJson(data));
} else {
configFilePublishService.createConfigFile(metadata, GsonUtils.getInstance().toJson(data));
}
Expand Down Expand Up @@ -89,7 +91,7 @@ public String getConfig(final String dataId) {

private boolean isReleased(final DefaultConfigFileMetadata metadata) {
try {
return configFileService.getConfigFile(metadata).getContent() != null;
return Objects.nonNull(configFileService.getConfigFile(metadata).getContent());
} catch (PolarisException e) {
LOG.error("Polaris Get data from polaris error.", e);
throw new ShenyuException(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public CuratorFramework getClient() {
*/
public boolean isExist(final String key) {
try {
return null != client.checkExists().forPath(key);
return Objects.nonNull(client.checkExists().forPath(key));
} catch (Exception e) {
return false;
}
Expand Down Expand Up @@ -181,7 +181,7 @@ public void createOrUpdate(final String key, final String value, final CreateMod
* @param mode creation mode.
*/
public void createOrUpdate(final String key, final Object value, final CreateMode mode) {
if (value != null) {
if (Objects.nonNull(value)) {
String val = GsonUtils.getInstance().toJson(value);
createOrUpdate(key, val, mode);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Objects;

/**
* this is selector controller.
*/
Expand Down Expand Up @@ -76,7 +78,7 @@ public AdminResult<CommonPager<SelectorVO>> querySelectors(final String pluginId
condition.setUserId(SessionUtil.visitor().getUserId());
condition.setPlugin(ListUtil.of(pluginId));
condition.setKeyword(name);
if (namespaceId != null) {
if (Objects.nonNull(namespaceId)) {
condition.setNamespaceId(namespaceId);
}
return searchAdaptor(new PageCondition<>(currentPage, pageSize, condition));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.sql.Timestamp;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.ArrayList;
Expand Down Expand Up @@ -107,7 +108,7 @@ public void createDiscovery(final DiscoveryDO discoveryDO) {
@Override
public void removeDiscovery(final DiscoveryDO discoveryDO) {
ShenyuDiscoveryService shenyuDiscoveryService = discoveryServiceCache.remove(discoveryDO.getId());
if (shenyuDiscoveryService == null) {
if (Objects.isNull(shenyuDiscoveryService)) {
return;
}
if (discoveryServiceCache.values().stream().noneMatch(p -> p.equals(shenyuDiscoveryService))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public CuratorFramework getClient() {
*/
public boolean isExist(final String key) {
try {
return null != client.checkExists().forPath(key);
return Objects.nonNull(client.checkExists().forPath(key));
} catch (Exception e) {
throw new ShenyuException(e);
}
Expand Down Expand Up @@ -182,7 +182,7 @@ public void createOrUpdate(final String key, final String value, final CreateMod
* @param mode creation mode.
*/
public void createOrUpdate(final String key, final Object value, final CreateMode mode) {
if (value != null) {
if (Objects.nonNull(value)) {
String val = GsonUtils.getInstance().toJson(value);
createOrUpdate(key, val, mode);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (Objects.isNull(o) || getClass() != o.getClass()) {
return false;
}
BatchCommonDTO that = (BatchCommonDTO) o;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (Objects.isNull(o) || getClass() != o.getClass()) {
return false;
}
BatchNamespaceCommonDTO that = (BatchNamespaceCommonDTO) o;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (Objects.isNull(o) || getClass() != o.getClass()) {
return false;
}
DetailDTO detailDTO = (DetailDTO) o;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (Objects.isNull(o) || getClass() != o.getClass()) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (Objects.isNull(o) || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (Objects.isNull(o) || getClass() != o.getClass()) {
return false;
}
MetaDataDTO that = (MetaDataDTO) o;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (Objects.isNull(o) || getClass() != o.getClass()) {
return false;
}
NamespacePluginDTO that = (NamespacePluginDTO) o;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (Objects.isNull(o) || getClass() != o.getClass()) {
return false;
}
PluginDTO pluginDTO = (PluginDTO) o;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (Objects.isNull(o) || getClass() != o.getClass()) {
return false;
}
ScalePolicyDTO that = (ScalePolicyDTO) o;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (Objects.isNull(o) || getClass() != o.getClass()) {
return false;
}
ScaleRuleDTO that = (ScaleRuleDTO) o;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (Objects.isNull(o) || getClass() != o.getClass()) {
return false;
}
SelectorDTO that = (SelectorDTO) o;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (Objects.isNull(o) || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (Objects.isNull(o) || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (Objects.isNull(o) || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (Objects.isNull(o) || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (Objects.isNull(o) || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (Objects.isNull(o) || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (Objects.isNull(o) || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (Objects.isNull(o) || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (Objects.isNull(o) || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (Objects.isNull(o) || getClass() != o.getClass()) {
return false;
}
NamespaceUserRelDO that = (NamespaceUserRelDO) o;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (Objects.isNull(o) || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (Objects.isNull(o) || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (Objects.isNull(o) || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (Objects.isNull(o) || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (Objects.isNull(o) || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
Expand Down
Loading

0 comments on commit 60676c1

Please sign in to comment.