Skip to content

Commit e446215

Browse files
committed
Apply checkstyle to test sources, fix violations
1 parent 8127ddf commit e446215

24 files changed

Lines changed: 108 additions & 66 deletions

checkstyle/checkstyle-config.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
<module name="Checker">
44
<module name="TreeWalker">
55
<module name="AvoidStarImport"/>
6+
<module name="HiddenField">
7+
<property name="tokens" value="VARIABLE_DEF"/>
8+
</module>
9+
<module name="MissingOverride"/>
610
<module name="NeedBraces"/>
11+
<module name="OneTopLevelClass"/>
712
</module>
813
<module name="RegexpHeader">
914
<property name="headerFile" value="checkstyle/header.template.txt"/>

pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@
320320
<googleJavaFormat>
321321
<version>${google-java-format.version}</version>
322322
</googleJavaFormat>
323+
<removeUnusedImports/>
324+
<importOrder/>
323325
</java>
324326
</configuration>
325327
</plugin>
@@ -343,6 +345,7 @@
343345
<configLocation>google_checks.xml</configLocation>
344346
-->
345347
<configLocation>checkstyle/checkstyle-config.xml</configLocation>
348+
<includeTestSourceDirectory>true</includeTestSourceDirectory>
346349
<linkXRef>false</linkXRef>
347350
<consoleOutput>true</consoleOutput>
348351
<failsOnError>true</failsOnError>

src/main/java/org/xbill/DNS/Address.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,22 @@ private static byte[] parseV6(String s) {
8686
int first = 0;
8787
int last = tokens.length - 1;
8888

89-
if (tokens[0].length() == 0) {
89+
if (tokens[0].isEmpty()) {
9090
// If the first two tokens are empty, it means the string
9191
// started with ::, which is fine. If only the first is
9292
// empty, the string started with :, which is bad.
93-
if (last - first > 0 && tokens[1].length() == 0) {
93+
if (last - first > 0 && tokens[1].isEmpty()) {
9494
first++;
9595
} else {
9696
return null;
9797
}
9898
}
9999

100-
if (tokens[last].length() == 0) {
100+
if (tokens[last].isEmpty()) {
101101
// If the last two tokens are empty, it means the string
102102
// ended with ::, which is fine. If only the last is
103103
// empty, the string ended with :, which is bad.
104-
if (last - first > 0 && tokens[last - 1].length() == 0) {
104+
if (last - first > 0 && tokens[last - 1].isEmpty()) {
105105
last--;
106106
} else {
107107
return null;
@@ -114,7 +114,7 @@ private static byte[] parseV6(String s) {
114114

115115
int i, j;
116116
for (i = first, j = 0; i <= last; i++) {
117-
if (tokens[i].length() == 0) {
117+
if (tokens[i].isEmpty()) {
118118
if (range >= 0) {
119119
return null;
120120
}

src/main/java/org/xbill/DNS/Cache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ private synchronized void removeElement(Name name, int type) {
297297
Element elt = list.get(i);
298298
if (elt.getType() == type) {
299299
list.remove(i);
300-
if (list.size() == 0) {
300+
if (list.isEmpty()) {
301301
data.remove(name);
302302
}
303303
return;

src/main/java/org/xbill/DNS/ExtendedErrorCodeOption.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ void optionFromWire(DNSInput in) throws IOException {
249249
@Override
250250
void optionToWire(DNSOutput out) {
251251
out.writeU16(errorCode);
252-
if (text != null && text.length() > 0) {
252+
if (text != null && !text.isEmpty()) {
253253
out.writeByteArray(text.getBytes(StandardCharsets.UTF_8));
254254
}
255255
}

src/main/java/org/xbill/DNS/NioUdpClient.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ public void processReadyKey(SelectionKey key) {
112112
return;
113113
}
114114

115-
DatagramChannel channel = (DatagramChannel) key.channel();
115+
DatagramChannel keyChannel = (DatagramChannel) key.channel();
116116
ByteBuffer buffer = ByteBuffer.allocate(max);
117117
int read;
118118
try {
119-
read = channel.read(buffer);
119+
read = keyChannel.read(buffer);
120120
if (read <= 0) {
121121
throw new EOFException();
122122
}
@@ -127,15 +127,15 @@ public void processReadyKey(SelectionKey key) {
127127
}
128128

129129
buffer.flip();
130-
byte[] data = new byte[read];
131-
System.arraycopy(buffer.array(), 0, data, 0, read);
130+
byte[] resultingData = new byte[read];
131+
System.arraycopy(buffer.array(), 0, resultingData, 0, read);
132132
verboseLog(
133133
"UDP read: transaction id=" + id,
134-
channel.socket().getLocalSocketAddress(),
135-
channel.socket().getRemoteSocketAddress(),
136-
data);
134+
keyChannel.socket().getLocalSocketAddress(),
135+
keyChannel.socket().getRemoteSocketAddress(),
136+
resultingData);
137137
silentCloseChannel();
138-
f.complete(data);
138+
f.complete(resultingData);
139139
pendingTransactions.remove(this);
140140
}
141141

src/main/java/org/xbill/DNS/Record.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ public String toString() {
343343
}
344344
sb.append(Type.string(type));
345345
String rdata = rrToString();
346-
if (!rdata.equals("")) {
346+
if (!rdata.isEmpty()) {
347347
sb.append("\t");
348348
sb.append(rdata);
349349
}

src/main/java/org/xbill/DNS/SVCBBase.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,11 @@ public ParameterAlpn(List<String> values) throws TextParseException {
236236
}
237237

238238
public List<String> getValues() {
239-
List<String> values = new ArrayList<>();
240-
for (byte[] b : this.values) {
241-
values.add(byteArrayToString(b, false));
239+
List<String> result = new ArrayList<>();
240+
for (byte[] b : values) {
241+
result.add(byteArrayToString(b, false));
242242
}
243-
return values;
243+
return result;
244244
}
245245

246246
@Override
@@ -394,14 +394,14 @@ public ParameterIpv4Hint(List<Inet4Address> addresses) {
394394
}
395395

396396
public List<Inet4Address> getAddresses() throws UnknownHostException {
397-
List<Inet4Address> addresses = new LinkedList<>();
398-
for (byte[] bytes : this.addresses) {
397+
List<Inet4Address> result = new LinkedList<>();
398+
for (byte[] bytes : addresses) {
399399
InetAddress address = InetAddress.getByAddress(bytes);
400400
if (address instanceof Inet4Address) {
401-
addresses.add((Inet4Address) address);
401+
result.add((Inet4Address) address);
402402
}
403403
}
404-
return addresses;
404+
return result;
405405
}
406406

407407
@Override
@@ -569,14 +569,14 @@ public ParameterIpv6Hint(List<Inet6Address> addresses) {
569569
}
570570

571571
public List<Inet6Address> getAddresses() throws UnknownHostException {
572-
List<Inet6Address> addresses = new LinkedList<>();
573-
for (byte[] bytes : this.addresses) {
572+
List<Inet6Address> result = new LinkedList<>();
573+
for (byte[] bytes : addresses) {
574574
InetAddress address = InetAddress.getByAddress(bytes);
575575
if (address instanceof Inet6Address) {
576-
addresses.add((Inet6Address) address);
576+
result.add((Inet6Address) address);
577577
}
578578
}
579-
return addresses;
579+
return result;
580580
}
581581

582582
@Override

src/main/java/org/xbill/DNS/Zone.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ private synchronized void removeRRset(Name name, int type) {
321321
RRset set = list.get(i);
322322
if (set.getType() == type) {
323323
list.remove(i);
324-
if (list.size() == 0) {
324+
if (list.isEmpty()) {
325325
data.remove(name);
326326
}
327327
return;

src/main/java/org/xbill/DNS/ZoneTransferIn.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,8 @@ public void run(ZoneTransferHandler handler) throws IOException, ZoneTransferExc
576576
* itself.
577577
*/
578578
public void run() throws IOException, ZoneTransferException {
579-
BasicHandler handler = new BasicHandler();
580-
run(handler);
579+
BasicHandler basicHandler = new BasicHandler();
580+
run(basicHandler);
581581
}
582582

583583
private BasicHandler getBasicHandler() throws IllegalArgumentException {
@@ -603,8 +603,8 @@ public boolean isAXFR() {
603603
* not stored.
604604
*/
605605
public List<Record> getAXFR() {
606-
BasicHandler handler = getBasicHandler();
607-
return handler.axfr;
606+
BasicHandler basicHandler = getBasicHandler();
607+
return basicHandler.axfr;
608608
}
609609

610610
/**
@@ -622,8 +622,8 @@ public boolean isIXFR() {
622622
* not stored.
623623
*/
624624
public List<Delta> getIXFR() {
625-
BasicHandler handler = getBasicHandler();
626-
return handler.ixfr;
625+
BasicHandler basicHandler = getBasicHandler();
626+
return basicHandler.ixfr;
627627
}
628628

629629
/**
@@ -634,7 +634,7 @@ public List<Delta> getIXFR() {
634634
* not stored.
635635
*/
636636
public boolean isCurrent() {
637-
BasicHandler handler = getBasicHandler();
638-
return handler.axfr == null && handler.ixfr == null;
637+
BasicHandler basicHandler = getBasicHandler();
638+
return basicHandler.axfr == null && basicHandler.ixfr == null;
639639
}
640640
}

0 commit comments

Comments
 (0)