Skip to content

Commit 7cef3e2

Browse files
committed
Fix bugs as reported by Sonar
1 parent 53a4fb9 commit 7cef3e2

File tree

7 files changed

+163
-165
lines changed

7 files changed

+163
-165
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ protected void rdataFromString(Tokenizer st, Name origin) throws IOException {
173173
vPrecision = parseDouble(st, "vertical precision", false, 0, 9000000000L, 1000);
174174
}
175175

176-
private void renderFixedPoint(StringBuffer sb, NumberFormat formatter, long value, long divisor) {
176+
private void renderFixedPoint(
177+
StringBuilder sb, NumberFormat formatter, long value, long divisor) {
177178
sb.append(value / divisor);
178179
value %= divisor;
179180
if (value != 0) {
@@ -183,7 +184,7 @@ private void renderFixedPoint(StringBuffer sb, NumberFormat formatter, long valu
183184
}
184185

185186
private String positionToString(long value, char pos, char neg) {
186-
StringBuffer sb = new StringBuffer();
187+
StringBuilder sb = new StringBuilder();
187188
char direction;
188189

189190
long temp = value - (1L << 31);
@@ -213,7 +214,7 @@ private String positionToString(long value, char pos, char neg) {
213214
/** Convert to a String */
214215
@Override
215216
protected String rrToString() {
216-
StringBuffer sb = new StringBuffer();
217+
StringBuilder sb = new StringBuilder();
217218

218219
/* Latitude */
219220
sb.append(positionToString(latitude, 'N', 'S'));
@@ -301,6 +302,6 @@ private int toLOCformat(long l) {
301302
exp++;
302303
l /= 10;
303304
}
304-
return (int) ((l << 4) + exp);
305+
return (int) ((l << 4) + (exp & 0xFF));
305306
}
306307
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ default void setEDNS(int version, int payloadSize, int flags, EDNSOption... opti
104104
*/
105105
@Deprecated
106106
default void setTimeout(int secs, int msecs) {
107-
setTimeout(Duration.ofMillis(secs * 1000 + msecs));
107+
setTimeout(Duration.ofMillis(secs * 1000L + msecs));
108108
}
109109

110110
/**

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
public class TcpKeepaliveOption extends EDNSOption {
1616

1717
/** the timeout */
18-
private OptionalInt timeout;
18+
private Integer timeout;
1919

2020
/** upper limit of the duration (exclusive) */
2121
private static final Duration UPPER_LIMIT = Duration.ofMillis(6553600);
2222

2323
/** Constructor for an option with no timeout */
2424
public TcpKeepaliveOption() {
2525
super(EDNSOption.Code.TCP_KEEPALIVE);
26-
timeout = OptionalInt.empty();
26+
timeout = null;
2727
}
2828

2929
/**
@@ -36,7 +36,7 @@ public TcpKeepaliveOption(int t) {
3636
if (t < 0 || t > 65535) {
3737
throw new IllegalArgumentException("timeout must be betwee 0 and 65535");
3838
}
39-
timeout = OptionalInt.of(t);
39+
timeout = t;
4040
}
4141

4242
/**
@@ -51,7 +51,7 @@ public TcpKeepaliveOption(Duration t) {
5151
throw new IllegalArgumentException(
5252
"timeout must be between 0 and 6553.6 seconds (exclusively)");
5353
}
54-
timeout = OptionalInt.of((int) t.toMillis() / 100);
54+
timeout = (int) t.toMillis() / 100;
5555
}
5656

5757
/**
@@ -60,7 +60,7 @@ public TcpKeepaliveOption(Duration t) {
6060
* @return the timeout in 100ms units
6161
*/
6262
public OptionalInt getTimeout() {
63-
return timeout;
63+
return timeout == null ? OptionalInt.empty() : OptionalInt.of(timeout);
6464
}
6565

6666
/**
@@ -69,9 +69,7 @@ public OptionalInt getTimeout() {
6969
* @return the timeout
7070
*/
7171
public Optional<Duration> getTimeoutDuration() {
72-
return timeout.isPresent()
73-
? Optional.of(Duration.ofMillis(timeout.getAsInt() * 100))
74-
: Optional.empty();
72+
return timeout != null ? Optional.of(Duration.ofMillis(timeout * 100L)) : Optional.empty();
7573
}
7674

7775
/**
@@ -86,10 +84,10 @@ void optionFromWire(DNSInput in) throws IOException {
8684

8785
switch (length) {
8886
case 0:
89-
timeout = OptionalInt.empty();
87+
timeout = null;
9088
break;
9189
case 2:
92-
timeout = OptionalInt.of(in.readU16());
90+
timeout = in.readU16();
9391
break;
9492
default:
9593
throw new WireParseException(
@@ -104,8 +102,8 @@ void optionFromWire(DNSInput in) throws IOException {
104102
*/
105103
@Override
106104
void optionToWire(DNSOutput out) {
107-
if (timeout.isPresent()) {
108-
out.writeU16(timeout.getAsInt());
105+
if (timeout != null) {
106+
out.writeU16(timeout);
109107
}
110108
}
111109

@@ -116,6 +114,6 @@ void optionToWire(DNSOutput out) {
116114
*/
117115
@Override
118116
String optionToString() {
119-
return timeout.isPresent() ? String.valueOf(timeout.getAsInt()) : "-";
117+
return timeout != null ? String.valueOf(timeout) : "-";
120118
}
121119
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class ZoneTransferIn {
6161
private TCPClient client;
6262
private TSIG tsig;
6363
private TSIG.StreamVerifier verifier;
64-
private long timeout = 900 * 1000;
64+
private long timeout = 900 * 1000L;
6565

6666
private int state;
6767
private long end_serial;

src/main/java/org/xbill/DNS/config/WindowsResolverConfigProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private static final class InnerWindowsResolverConfigProvider extends BaseResolv
5858
public void initialize() throws InitializationException {
5959
// The recommended method of calling the GetAdaptersAddresses function is to pre-allocate a
6060
// 15KB working buffer
61-
Memory buffer = new Memory(15 * 1024);
61+
Memory buffer = new Memory(15 * 1024L);
6262
IntByReference size = new IntByReference(0);
6363
int flags =
6464
GAA_FLAG_SKIP_UNICAST

0 commit comments

Comments
 (0)