Skip to content

Commit 85469de

Browse files
committed
small refactor/cleanup: 🧹
- use `isEmpty()` for `String` instead of `length() == 0` - add `@SuppressWarnings("JavadocReference")`/`@SuppressWarnings("JavadocReference")` for expected cases
1 parent c7f7fd2 commit 85469de

File tree

12 files changed

+20
-20
lines changed

12 files changed

+20
-20
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ int cachePolicy = DnsCacheManipulator.getDnsCachePolicy();
222222
DnsCacheManipulator.setDnsCachePolicy(2);
223223

224224
// View the cache time of missed entries(negative entries)
225-
DnsCacheManipulator.getDnsNegativeCachePolicy()
225+
DnsCacheManipulator.getDnsNegativeCachePolicy();
226226
// Set the cache time of missed entries
227227
DnsCacheManipulator.setDnsNegativeCachePolicy(0);
228228
```
@@ -233,7 +233,7 @@ DnsCacheManipulator.setDnsNegativeCachePolicy(0);
233233

234234
With the release of Java 16 the access control of the new Jigsaw module system is starting to be enforced by the JVM. If you use `DCM` under Java 16+, add below Java options:
235235

236-
```java
236+
```sh
237237
--add-opens java.base/java.net=ALL-UNNAMED
238238
--add-opens java.base/sun.net=ALL-UNNAMED
239239
```

docs/developer-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,4 @@ The LTS `JDK` versions(8/11/17) and recent versions are tested , other `JDK` ver
7979
- [FileOutput Node - Java DNS caching pitfall - quick clarification and tips](https://www.ibm.com/developerworks/community/blogs/aimsupport/entry/fileoutput_node_dns_caching_pitfall?lang=en)
8080
- The [`javahost`](https://github.com/tanhaichao/javahost) project of [`@tanhaichao`](https://github.com/tanhaichao) (Thanks for your work!)
8181
- [the documentation](http://leopard.io/modules/javahost) of the project.
82-
- The solution of how to set up Java DNS Cache in this project comes from this project. When I first encountered the host binding problem in the continuous integration project, I also used the project to solve it 👍
82+
- The solution of how to set up Java DNS Cache comes from this project. When I first encountered the host binding problem in the continuous integration project, I also used the project to solve it 👍

docs/zh-CN/library.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Java Dns Cache Manipulator(DCM) Library
7474
- 一个`JVM`进程可以对应一套域名绑定,相互之间不影响,可以实现多场景,多域名绑定的需求压测。
7575
1. 打开`Java`中的`SecurityManager`时(如在`Web`容器`Tomcat`中的`Web`应用),`Java``DNS`缺省是不会失效的。
7676
如果域名绑定的`IP`变了,可以通过这个库重置`DNS`
77-
- 通过[`Java Dns Cache Manipulator Tool`](../tool)设置运行中`JVM DNS Cache`
77+
- 通过[`Java Dns Cache Manipulator Tool`](../../tool)设置运行中`JVM DNS Cache`
7878
**无需** 应用包含了`Java Dns Cache Manipulator Library`依赖(即`Jar`)。
7979
- 或通过执行入口调用`Java Dns Cache Manipulator Library`的方法,比如远程调用或是[`jvm-ssh-groovy-shell`](https://github.com/palominolabs/jvm-ssh-groovy-shell)
8080
***需要*** 应用已经包含了`Java Dns Cache Manipulator Library`依赖(即`Jar`)。
@@ -170,7 +170,7 @@ DnsCacheManipulator.removeDnsCache("aliyun.com");
170170
----------------------------------
171171

172172
```java
173-
DnsCache dnsCache = DnsCacheManipulator.getWholeDnsCache()
173+
DnsCache dnsCache = DnsCacheManipulator.getWholeDnsCache();
174174
System.out.println(dnsCache);
175175
```
176176

@@ -184,7 +184,7 @@ int cachePolicy = DnsCacheManipulator.getDnsCachePolicy();
184184
DnsCacheManipulator.setDnsCachePolicy(2);
185185

186186
// 查看未命中条目的缓存时间
187-
DnsCacheManipulator.getDnsNegativeCachePolicy()
187+
DnsCacheManipulator.getDnsNegativeCachePolicy();
188188
// 设置未命中条目的缓存时间
189189
DnsCacheManipulator.setDnsNegativeCachePolicy(0);
190190
```

library/src/main/java/com/alibaba/dcm/DnsCache.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ public List<DnsCacheEntry> getNegativeCache() {
5555
*/
5656
@Override
5757
public String toString() {
58-
return "DnsCache{" +
59-
"cache=" + cache +
60-
", negativeCache=" + negativeCache +
61-
'}';
58+
return "DnsCache{cache=" + cache + ", negativeCache=" + negativeCache + '}';
6259
}
6360

6461
/**

library/src/main/java/com/alibaba/dcm/DnsCacheEntry.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,8 @@ public DnsCacheEntry(String host,
9191
public String toString() {
9292
final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
9393

94-
return "DnsCacheEntry{" +
95-
"host='" + host + '\'' +
96-
", ips=" + Arrays.toString(ips) +
97-
", expiration=" + dateFormat.format(expiration) +
98-
'}';
94+
return "DnsCacheEntry{host='" + host + '\'' + ", ips=" + Arrays.toString(ips) +
95+
", expiration=" + dateFormat.format(expiration) + '}';
9996
}
10097

10198
/**
@@ -120,7 +117,7 @@ public boolean equals(Object o) {
120117
public int hashCode() {
121118
int result = host != null ? host.hashCode() : 0;
122119
result = 31 * result + Arrays.hashCode(ips);
123-
result = 31 * result + (int) (expiration ^ (expiration >>> 32));
120+
result = 31 * result + Long.hashCode(expiration);
124121
return result;
125122
}
126123
}

library/src/main/java/com/alibaba/dcm/DnsCacheManipulator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
*/
3232
@ParametersAreNonnullByDefault
3333
@ReturnValuesAreNonnullByDefault
34+
@SuppressWarnings("JavadocReference")
3435
public final class DnsCacheManipulator {
3536
/**
3637
* Set a <b>never expired</b> dns cache entry.

library/src/main/java/com/alibaba/dcm/agent/DcmAgent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ private static boolean isDcmAgentSuppressExceptionStack() {
163163
if (suppressException == null) return false;
164164

165165
suppressException = suppressException.trim();
166-
if (suppressException.length() == 0) return false;
166+
if (suppressException.isEmpty()) return false;
167167

168168
return "true".equalsIgnoreCase(suppressException);
169169
}
@@ -300,7 +300,7 @@ public static List<String> getActionList() {
300300
@Nullable
301301
private static String getConfig(@Nonnull String name) {
302302
String var = System.getenv(name);
303-
if (var == null || var.trim().length() == 0) {
303+
if (var == null || var.trim().isEmpty()) {
304304
var = System.getProperty(name);
305305
}
306306
return var;

library/src/main/java/com/alibaba/dcm/internal/InetAddressCacheUtilCommons.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
@ParametersAreNonnullByDefault
2020
@ReturnValuesAreNonnullByDefault
2121
@ApiStatus.Internal
22+
@SuppressWarnings("JavadocReference")
2223
public final class InetAddressCacheUtilCommons {
2324
/**
2425
* We never really have "never".

library/src/main/java/com/alibaba/dcm/internal/InetAddressCacheUtilForNew.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
@ParametersAreNonnullByDefault
3636
@ReturnValuesAreNonnullByDefault
3737
@ApiStatus.Internal
38+
@SuppressWarnings("JavadocReference")
3839
public final class InetAddressCacheUtilForNew {
3940
/**
4041
* {@link InetAddress.CachedAddresses}

library/src/main/java/com/alibaba/dcm/internal/InetAddressCacheUtilForOld.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
@ParametersAreNonnullByDefault
4242
@ReturnValuesAreNonnullByDefault
4343
@ApiStatus.Internal
44+
@SuppressWarnings("JavadocReference")
4445
public final class InetAddressCacheUtilForOld {
4546
/**
4647
* Need convert host to lowercase, see {@link InetAddress#cacheAddresses(String, InetAddress[], boolean)}.
@@ -170,6 +171,7 @@ private static Object getNegativeCacheOfInetAddress()
170171
/**
171172
* @return {@link InetAddress#addressCache} and {@link InetAddress#negativeCache}
172173
*/
174+
@SuppressWarnings("JavaReflectionMemberAccess")
173175
private static Object[] getAddressCacheAndNegativeCacheOfInetAddress0()
174176
throws NoSuchFieldException, IllegalAccessException {
175177
if (ADDRESS_CACHE_AND_NEGATIVE_CACHE != null) return ADDRESS_CACHE_AND_NEGATIVE_CACHE;

0 commit comments

Comments
 (0)