Skip to content

Commit fbb6b09

Browse files
committed
Fix or suppress Sonar-reported issues
1 parent 77e0495 commit fbb6b09

108 files changed

Lines changed: 901 additions & 741 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/actions/download-artifact/action.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ runs:
2424

2525
- name: Download artifacts
2626
if: github.event_name == 'workflow_run'
27-
uses: dawidd6/action-download-artifact@v6
27+
uses: dawidd6/action-download-artifact@v7
2828
with:
2929
workflow: ${{ github.event.workflow_run.name }}
3030
run_id: ${{ github.event.workflow_run.id }}
@@ -33,6 +33,7 @@ runs:
3333
name_is_regexp: true
3434

3535
- name: Extract artifacts
36+
if: github.event_name != 'workflow_run'
3637
run: |
3738
for t in ${{ inputs.name }}*.tar
3839
do
@@ -41,7 +42,20 @@ runs:
4142
shell: bash
4243
working-directory: ${{ inputs.path }}
4344

45+
- name: Extract artifacts
46+
if: github.event_name == 'workflow_run'
47+
run: |
48+
for t in ${{ inputs.name }}/${{ inputs.name }}*.tar
49+
do
50+
mv "${t}" .
51+
tar -xvf "${t}"
52+
done
53+
shell: bash
54+
working-directory: ${{ inputs.path }}
55+
4456
- name: Remove archive
45-
run: rm -f ${{ inputs.name }}*.tar
57+
run: |
58+
rm -f ${{ inputs.name }}.tar
59+
rm -f ${{ inputs.name }}.zip
4660
shell: bash
4761
working-directory: ${{ inputs.path }}

.github/workflows/analyze.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,5 @@ jobs:
8686
-Dsonar.pullrequest.key='${WF_PRKEY}' \
8787
-Dsonar.pullrequest.branch='${WF_BRANCH}' \
8888
-Dsonar.pullrequest.base='${WF_BASE}' \
89+
properties:read-project-properties \
8990
org.sonarsource.scanner.maven:sonar-maven-plugin:sonar

.github/workflows/build.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,7 @@ jobs:
164164
cache: maven
165165

166166
- name: Run codecov
167-
uses: codecov/codecov-action@v4
168-
env:
169-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
167+
uses: codecov/codecov-action@v5
170168

171169
# doesn't work with PRs from forks, see
172170
# https://portal.productboard.com/sonarsource/1-sonarcloud/c/50-sonarcloud-analyzes-external-pull-request
@@ -175,7 +173,7 @@ jobs:
175173
env:
176174
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
177175
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
178-
run: mvn -B org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
176+
run: mvn -B properties:read-project-properties org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
179177

180178
release:
181179
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release/')

pom.xml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,31 @@
6161
<google-java-format.version>1.7</google-java-format.version>
6262
<spotless.version>2.30.0</spotless.version>
6363

64-
<sonar.projectKey>dnsjava_dnsjava</sonar.projectKey>
65-
<sonar.organization>dnsjava</sonar.organization>
66-
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
67-
<sonar.java.source>${target.jdk}</sonar.java.source>
68-
<sonar.coverage.jacoco.xmlReportPaths>${project.build.directory}/site/jacoco/jacoco.xml
69-
</sonar.coverage.jacoco.xmlReportPaths>
64+
<sonar.coverage.jacoco.xmlReportPaths>${project.build.directory}/site/jacoco/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
7065
<delombok.output>${project.build.directory}/delombok</delombok.output>
7166
</properties>
7267

7368
<build>
7469
<plugins>
70+
<plugin>
71+
<groupId>org.codehaus.mojo</groupId>
72+
<artifactId>properties-maven-plugin</artifactId>
73+
<version>1.2.1</version>
74+
<executions>
75+
<execution>
76+
<phase>initialize</phase>
77+
<goals>
78+
<goal>read-project-properties</goal>
79+
</goals>
80+
</execution>
81+
</executions>
82+
<configuration>
83+
<files>
84+
<file>sonar-project.properties</file>
85+
</files>
86+
</configuration>
87+
</plugin>
88+
7589
<plugin>
7690
<groupId>org.apache.maven.plugins</groupId>
7791
<artifactId>maven-gpg-plugin</artifactId>

sonar-project.properties

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
sonar.projectKey=dnsjava_dnsjava
2+
sonar.organization=dnsjava
3+
sonar.host.url=https://sonarcloud.io
4+
sonar.java.source=8
5+
sonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml
6+
7+
sonar.issue.ignore.multicriteria=S106,S107,S120,S1948,S2160
8+
9+
# Standard outputs should not be used directly to log anything
10+
# The tools are intended for command line usage, it's not logging
11+
sonar.issue.ignore.multicriteria.S106.ruleKey=java:S106
12+
sonar.issue.ignore.multicriteria.S106.resourceKey=**/tools/*.java
13+
14+
# Package names should comply with a naming convention
15+
# org.xbill.DNS - api compatibility
16+
sonar.issue.ignore.multicriteria.S120.ruleKey=java:S120
17+
sonar.issue.ignore.multicriteria.S120.resourceKey=**
18+
19+
# Methods should not have too many parameters
20+
# The Record implementations have these for their definition
21+
sonar.issue.ignore.multicriteria.S107.ruleKey=java:S107
22+
sonar.issue.ignore.multicriteria.S107.resourceKey=**/*Record.java
23+
24+
# Fields in a "Serializable" class should either be transient or serializable
25+
# Serialization should use the wire format, supported for EJB scenarios. See
26+
# https://github.com/dnsjava/dnsjava/issues/114
27+
# https://github.com/dnsjava/dnsjava/issues/132
28+
sonar.issue.ignore.multicriteria.S1948.ruleKey=java:S1948
29+
sonar.issue.ignore.multicriteria.S1948.resourceKey=**/*Record.java
30+
31+
# Subclasses that add fields to classes that override "equals" should also override "equals"
32+
# The Record base class implements equals based on the record's wire format
33+
sonar.issue.ignore.multicriteria.S2160.ruleKey=java:S2160
34+
sonar.issue.ignore.multicriteria.S2160.resourceKey=**/*Record.java
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// SPDX-License-Identifier: BSD-3-Clause
22
package android.net;
33

4+
@SuppressWarnings("java:S2094")
45
public class Network {}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@
44
package org.xbill.DNS;
55

66
import java.io.IOException;
7+
import java.io.Serializable;
78
import java.net.InetAddress;
89
import java.util.ArrayList;
910
import java.util.Iterator;
1011
import java.util.List;
1112
import org.xbill.DNS.utils.base16;
1213

13-
/*
14-
* Note: this currently uses the same constants as the Address class;
15-
* this could change if more constants are defined for APL records.
16-
*/
17-
1814
/**
1915
* APL - Address Prefix List.
2016
*
@@ -24,7 +20,7 @@
2420
*/
2521
public class APLRecord extends Record {
2622

27-
public static class Element {
23+
public static class Element implements Serializable {
2824
public final int family;
2925
public final boolean negative;
3026
public final int prefixLength;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,6 @@ public InetAddress getAddress() {
9393

9494
@Override
9595
protected void rrToWire(DNSOutput out, Compression c, boolean canonical) {
96-
out.writeU32((long) addr & 0xFFFFFFFFL);
96+
out.writeU32(addr & 0xFFFFFFFFL);
9797
}
9898
}

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

Lines changed: 5 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -7,173 +7,20 @@
77
import java.net.Inet6Address;
88
import java.net.InetAddress;
99
import java.net.UnknownHostException;
10+
import lombok.experimental.UtilityClass;
1011

1112
/**
1213
* Routines dealing with IP addresses. Includes functions similar to those in the
1314
* java.net.InetAddress class.
1415
*
1516
* @author Brian Wellington
1617
*/
18+
@UtilityClass
1719
public final class Address {
1820

1921
public static final int IPv4 = 1;
2022
public static final int IPv6 = 2;
2123

22-
private Address() {}
23-
24-
private static byte[] parseV4(String s) {
25-
int numDigits;
26-
int currentOctet;
27-
byte[] values = new byte[4];
28-
int currentValue;
29-
int length = s.length();
30-
31-
currentOctet = 0;
32-
currentValue = 0;
33-
numDigits = 0;
34-
for (int i = 0; i < length; i++) {
35-
char c = s.charAt(i);
36-
if (c >= '0' && c <= '9') {
37-
/* Can't have more than 3 digits per octet. */
38-
if (numDigits == 3) {
39-
return null;
40-
}
41-
/* Octets shouldn't start with 0, unless they are 0. */
42-
if (numDigits > 0 && currentValue == 0) {
43-
return null;
44-
}
45-
numDigits++;
46-
currentValue *= 10;
47-
currentValue += c - '0';
48-
/* 255 is the maximum value for an octet. */
49-
if (currentValue > 255) {
50-
return null;
51-
}
52-
} else if (c == '.') {
53-
/* Can't have more than 3 dots. */
54-
if (currentOctet == 3) {
55-
return null;
56-
}
57-
/* Two consecutive dots are bad. */
58-
if (numDigits == 0) {
59-
return null;
60-
}
61-
values[currentOctet++] = (byte) currentValue;
62-
currentValue = 0;
63-
numDigits = 0;
64-
} else {
65-
return null;
66-
}
67-
}
68-
/* Must have 4 octets. */
69-
if (currentOctet != 3) {
70-
return null;
71-
}
72-
/* The fourth octet can't be empty. */
73-
if (numDigits == 0) {
74-
return null;
75-
}
76-
values[currentOctet] = (byte) currentValue;
77-
return values;
78-
}
79-
80-
private static byte[] parseV6(String s) {
81-
int range = -1;
82-
byte[] data = new byte[16];
83-
84-
String[] tokens = s.split(":", -1);
85-
86-
int first = 0;
87-
int last = tokens.length - 1;
88-
89-
if (tokens[0].isEmpty()) {
90-
// If the first two tokens are empty, it means the string
91-
// started with ::, which is fine. If only the first is
92-
// empty, the string started with :, which is bad.
93-
if (last - first > 0 && tokens[1].isEmpty()) {
94-
first++;
95-
} else {
96-
return null;
97-
}
98-
}
99-
100-
if (tokens[last].isEmpty()) {
101-
// If the last two tokens are empty, it means the string
102-
// ended with ::, which is fine. If only the last is
103-
// empty, the string ended with :, which is bad.
104-
if (last - first > 0 && tokens[last - 1].isEmpty()) {
105-
last--;
106-
} else {
107-
return null;
108-
}
109-
}
110-
111-
if (last - first + 1 > 8) {
112-
return null;
113-
}
114-
115-
int i, j;
116-
for (i = first, j = 0; i <= last; i++) {
117-
if (tokens[i].isEmpty()) {
118-
if (range >= 0) {
119-
return null;
120-
}
121-
range = j;
122-
continue;
123-
}
124-
125-
if (tokens[i].indexOf('.') >= 0) {
126-
// An IPv4 address must be the last component
127-
if (i < last) {
128-
return null;
129-
}
130-
// There can't have been more than 6 components.
131-
if (i > 6) {
132-
return null;
133-
}
134-
byte[] v4addr = Address.toByteArray(tokens[i], IPv4);
135-
if (v4addr == null) {
136-
return null;
137-
}
138-
for (int k = 0; k < 4; k++) {
139-
data[j++] = v4addr[k];
140-
}
141-
break;
142-
}
143-
144-
try {
145-
for (int k = 0; k < tokens[i].length(); k++) {
146-
char c = tokens[i].charAt(k);
147-
if (Character.digit(c, 16) < 0) {
148-
return null;
149-
}
150-
}
151-
int x = Integer.parseInt(tokens[i], 16);
152-
if (x > 0xFFFF || x < 0) {
153-
return null;
154-
}
155-
data[j++] = (byte) (x >>> 8);
156-
data[j++] = (byte) (x & 0xFF);
157-
} catch (NumberFormatException e) {
158-
return null;
159-
}
160-
}
161-
162-
if (j < 16 && range < 0) {
163-
return null;
164-
}
165-
166-
if (range >= 0) {
167-
int empty = 16 - j;
168-
System.arraycopy(data, range, data, range + empty, j - range);
169-
for (i = range; i < range + empty; i++) {
170-
data[i] = 0;
171-
}
172-
}
173-
174-
return data;
175-
}
176-
17724
/**
17825
* Convert a string containing an IP address to an array of 4 or 16 integers.
17926
*
@@ -212,9 +59,9 @@ public static int[] toArray(String s) {
21259
*/
21360
public static byte[] toByteArray(String s, int family) {
21461
if (family == IPv4) {
215-
return parseV4(s);
62+
return IPAddressUtils.parseV4(s);
21663
} else if (family == IPv6) {
217-
return parseV6(s);
64+
return IPAddressUtils.parseV6(s);
21865
} else {
21966
throw new IllegalArgumentException("unknown address family");
22067
}
@@ -450,7 +297,7 @@ public static InetAddress truncate(InetAddress address, int maskLength) {
450297
for (int i = 0; i < maskBits; i++) {
451298
bitmask |= 1 << (7 - i);
452299
}
453-
bytes[maskLength / 8] &= bitmask;
300+
bytes[maskLength / 8] &= (byte) bitmask;
454301
try {
455302
return InetAddress.getByAddress(bytes);
456303
} catch (UnknownHostException e) {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ public static int value(String s) {
102102
/** Certificate format defined by IOD */
103103
public static final int OID = CertificateType.OID;
104104

105-
private int certType, keyTag;
105+
private int certType;
106+
private int keyTag;
106107
private int alg;
107108
private byte[] cert;
108109

@@ -159,7 +160,7 @@ protected String rrToString() {
159160
sb.append(" ");
160161
sb.append(alg);
161162
if (cert != null) {
162-
if (Options.check("multiline")) {
163+
if (Options.multiline()) {
163164
sb.append(" (\n");
164165
sb.append(base64.formatString(cert, 64, "\t", true));
165166
} else {

0 commit comments

Comments
 (0)