Skip to content
Permalink
Browse files

Add Error Prone and bump minimum Android SDK to 19

mostly for the StandardCharsets API.
  • Loading branch information...
Flowdalic committed Sep 16, 2019
1 parent c9d2969 commit a5c94b75cace679ea5e63265bfe958a0af014cd6
Showing with 69 additions and 27 deletions.
  1. +1 −1 .travis.yml
  2. +25 −1 build.gradle
  3. +1 −0 minidns-async/src/main/java/org/minidns/source/async/AsyncDnsRequest.java
  4. +1 −0 minidns-async/src/main/java/org/minidns/source/async/AsyncNetworkDataSource.java
  5. +1 −0 minidns-client/src/main/java/org/minidns/MiniDnsFuture.java
  6. +2 −1 minidns-client/src/main/java/org/minidns/MiniDnsInitialization.java
  7. +1 −0 minidns-client/src/main/java/org/minidns/cache/ExtendedLruCache.java
  8. +2 −1 minidns-client/src/main/java/org/minidns/dnsserverlookup/AndroidUsingExec.java
  9. +2 −1 minidns-client/src/main/java/org/minidns/dnsserverlookup/UnixUsingEtcResolvConf.java
  10. +2 −1 minidns-core/src/main/java/org/minidns/dnslabel/DnsLabel.java
  11. +3 −2 minidns-core/src/main/java/org/minidns/dnsname/DnsName.java
  12. +3 −1 minidns-core/src/main/java/org/minidns/edns/Nsid.java
  13. +1 −1 minidns-core/src/main/java/org/minidns/record/Data.java
  14. +1 −0 minidns-core/src/main/java/org/minidns/record/NSEC.java
  15. +1 −1 minidns-core/src/main/java/org/minidns/record/Record.java
  16. +1 −0 minidns-core/src/main/java/org/minidns/util/NameUtil.java
  17. +2 −2 minidns-core/src/test/java/org/minidns/dnsmessage/DnsMessageTest.java
  18. +4 −4 minidns-core/src/test/java/org/minidns/dnsname/DnsNameTest.java
  19. +5 −5 minidns-dnssec/src/main/java/org/minidns/dnssec/DnssecClient.java
  20. +2 −1 minidns-dnssec/src/test/java/org/minidns/dnssec/algorithms/DigestTest.java
  21. +2 −2 minidns-integration-test/src/main/java/org/minidns/integrationtest/NsidTest.java
  22. +3 −1 minidns-integration-test/src/main/java/org/minidns/jul/MiniDnsJul.java
  23. +2 −0 minidns-iterative-resolver/src/main/java/org/minidns/iterative/IterativeDnsClient.java
  24. +1 −1 version.gradle
@@ -1,7 +1,7 @@
language: android
android:
components:
- android-9
- android-19
- android-21
jdk:
- oraclejdk8
@@ -15,6 +15,7 @@ buildscript {

plugins {
id 'ru.vyarus.animalsniffer' version '1.5.0'
id 'net.ltgt.errorprone' version '0.8.1'
}

apply from: 'version.gradle'
@@ -25,6 +26,7 @@ allprojects {
apply plugin: 'osgi'
apply plugin: 'checkstyle'
apply plugin: 'jacoco'
apply plugin: 'net.ltgt.errorprone'

group = 'org.minidns'
description = "A minimal DNS client library with support for A, AAAA, NS and SRV records"
@@ -93,6 +95,25 @@ allprojects {
'-Xlint:-options',
'-Werror',
]
options.errorprone {
error(
"UnusedVariable",
"UnusedMethod",
"MethodCanBeStatic",
)
errorproneArgs = [
// Disable errorprone checks
'-Xep:TypeParameterUnusedInFormals:OFF',
// Disable errorpone StringSplitter check, as it
// recommends using Splitter from Guava, which we don't
// have (nor want to use in Smack).
'-Xep:StringSplitter:OFF',
'-Xep:JdkObsolete:OFF',
'-Xep:MixedMutabilityReturnType:OFF',
'-Xep:ImmutableEnumChecker:OFF',
]
}

}

checkstyle {
@@ -141,6 +162,9 @@ allprojects {
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"

errorprone 'com.google.errorprone:error_prone_core:2.3.3'
errorproneJavac('com.google.errorprone:javac:9+181-r4173-1')
}

}
@@ -243,7 +267,7 @@ subprojects {
configure(subprojects.findAll{!it.name.endsWith('-java7') && !it.name.endsWith('-android21')}) {
apply plugin: 'ru.vyarus.animalsniffer'
dependencies {
signature "net.sf.androidscents.signature:android-api-level-${minidnsMinAndroidSdk}:2.3.1_r2@signature"
signature "net.sf.androidscents.signature:android-api-level-${minidnsMinAndroidSdk}:4.4.2_r4@signature"
}
animalsniffer {
sourceSets = [sourceSets.main]
@@ -42,6 +42,7 @@
private static final Logger LOGGER = Logger.getLogger(AsyncDnsRequest.class.getName());

private final InternalMiniDnsFuture<DnsQueryResult, IOException> future = new InternalMiniDnsFuture<DnsQueryResult, IOException>() {
@SuppressWarnings("UnsynchronizedOverridesSynchronized")
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
boolean res = super.cancel(mayInterruptIfRunning);
@@ -153,6 +153,7 @@ private static void handleSelectedKeys(Collection<SelectionKey> selectedKeys) {
}
}

@SuppressWarnings("LockNotBeforeTry")
private static Collection<SelectionKey> performSelect() {
AsyncDnsRequest nearestDeadline = null;
AsyncDnsRequest nextInQueue;
@@ -177,6 +177,7 @@ public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
EXECUTOR_SERVICE = executorService;
}

@SuppressWarnings("FutureReturnValueIgnored")
protected final synchronized void maybeInvokeCallbacks() {
if (cancelled) {
return;
@@ -14,6 +14,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.logging.Level;
import java.util.logging.Logger;

@@ -28,7 +29,7 @@
BufferedReader reader = null;
try {
InputStream is = MiniDnsInitialization.class.getClassLoader().getResourceAsStream("org.minidns/version");
reader = new BufferedReader(new InputStreamReader(is));
reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
miniDnsVersion = reader.readLine();
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Could not determine MiniDNS version", e);
@@ -42,6 +42,7 @@ public ExtendedLruCache(int capacity, long maxTTL) {
super(capacity, maxTTL);
}

@SuppressWarnings("UnsynchronizedOverridesSynchronized")
@Override
protected void putNormalized(DnsMessage q, DnsQueryResult result) {
super.putNormalized(q, result);
@@ -19,6 +19,7 @@
import java.io.LineNumberReader;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -43,7 +44,7 @@ private AndroidUsingExec() {
Process process = Runtime.getRuntime().exec("getprop");
InputStream inputStream = process.getInputStream();
LineNumberReader lnr = new LineNumberReader(
new InputStreamReader(inputStream));
new InputStreamReader(inputStream, StandardCharsets.UTF_8));
Set<String> server = parseProps(lnr, true);
if (server.size() > 0) {
List<String> res = new ArrayList<>(server.size());
@@ -17,6 +17,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
@@ -57,7 +58,7 @@ private UnixUsingEtcResolvConf() {
List<String> servers = new ArrayList<>();
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
String line;
while ((line = reader.readLine()) != null) {
Matcher matcher = NAMESERVER_PATTERN.matcher(line);
@@ -11,6 +11,7 @@
package org.minidns.dnslabel;

import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Locale;

/**
@@ -120,7 +121,7 @@ public final DnsLabel asLowercaseVariant() {

private void setBytesIfRequired() {
if (byteCache == null) {
byteCache = label.getBytes();
byteCache = label.getBytes(StandardCharsets.US_ASCII);
}
}

@@ -15,6 +15,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Locale;
@@ -428,7 +429,7 @@ public static DnsName parse(DataInputStream dis, byte[] data)
byte[] b = new byte[c];
dis.readFully(b);

String childLabelString = new String(b);
String childLabelString = new String(b, StandardCharsets.US_ASCII);
DnsName child = new DnsName(childLabelString);

DnsName parent = parse(dis, data);
@@ -459,7 +460,7 @@ private static DnsName parse(byte[] data, int offset, HashSet<Integer> jumps)
return DnsName.ROOT;
}

String childLabelString = new String(data, offset + 1, c);
String childLabelString = new String(data, offset + 1, c, StandardCharsets.US_ASCII);
DnsName child = new DnsName(childLabelString);

DnsName parent = parse(data, offset + 1 + c, jumps);
@@ -10,6 +10,8 @@
*/
package org.minidns.edns;

import java.nio.charset.StandardCharsets;

import org.minidns.edns.Edns.OptionCode;
import org.minidns.util.Hex;

@@ -33,7 +35,7 @@ public OptionCode getOptionCode() {
@Override
protected CharSequence toStringInternal() {
String res = OptionCode.NSID + ": ";
res += new String(optionData);
res += new String(optionData, StandardCharsets.US_ASCII);
return res;
}

@@ -85,7 +85,7 @@ public final void toOutputStream(DataOutputStream dos) throws IOException {
public final int hashCode() {
if (hashCodeCache == null) {
setBytes();
hashCodeCache = bytes.hashCode();
hashCodeCache = Arrays.hashCode(bytes);
}
return hashCodeCache;
}
@@ -87,6 +87,7 @@ public String toString() {
return sb.toString();
}

@SuppressWarnings("NarrowingCompoundAssignment")
static byte[] createTypeBitMap(List<TYPE> types) {
List<Integer> typeList = new ArrayList<Integer>(types.size());
for (TYPE type : types) {
@@ -486,7 +486,7 @@ public String toString() {
public boolean isAnswer(Question q) {
return ((q.type == type) || (q.type == TYPE.ANY)) &&
((q.clazz == clazz) || (q.clazz == CLASS.ANY)) &&
(q.name.equals(name));
q.name.equals(name);
}

/**
@@ -25,6 +25,7 @@
* @param name2 The second domain name.
* @return True if both domain names are the same.
*/
@SuppressWarnings("ReferenceEquality")
public static boolean idnEquals(String name1, String name2) {
if (name1 == name2) return true; // catches null, null
if (name1 == null) return false;
@@ -87,7 +87,7 @@ public void testALookup() throws Exception {
assertTrue(cname.getPayload() instanceof RRWithTarget);
assertEquals(TYPE.CNAME, cname.getPayload().getType());
assertCsEquals("legacy-sun.oraclegha.com",
((RRWithTarget) (cname.getPayload())).target);
((RRWithTarget) cname.getPayload()).target);

assertCsEquals("legacy-sun.oraclegha.com", a.name);
assertTrue(a.getPayload() instanceof A);
@@ -141,7 +141,7 @@ public void testSRVLookup() throws Exception {
Record<? extends Data> answer = answers.get(0);
assertTrue(answer.getPayload() instanceof SRV);
assertEquals(TYPE.SRV, answer.getPayload().getType());
SRV r = (SRV) (answer.getPayload());
SRV r = (SRV) answer.getPayload();
assertCsEquals("raven.toroid.org", r.target);
assertEquals(5222, r.port);
assertEquals(0, r.priority);
@@ -27,10 +27,10 @@

@Test
public void sizeTest() {
assertEquals(1, (DnsName.from("")).size());
assertEquals(13, (DnsName.from("example.com")).size());
assertEquals(16, (DnsName.from("dömäin")).size());
assertEquals(24, (DnsName.from("dömäin.example")).size());
assertEquals(1, DnsName.from("").size());
assertEquals(13, DnsName.from("example.com").size());
assertEquals(16, DnsName.from("dömäin").size());
assertEquals(24, DnsName.from("dömäin.example").size());
}

@Test
@@ -102,11 +102,11 @@ public DnssecQueryResult queryDnssec(CharSequence name, TYPE type) throws IOExce

public DnssecQueryResult queryDnssec(Question q) throws IOException {
DnsQueryResult dnsQueryResult = super.query(q);
DnssecQueryResult dnssecQueryResult = performVerification(q, dnsQueryResult);
DnssecQueryResult dnssecQueryResult = performVerification(dnsQueryResult);
return dnssecQueryResult;
}

private DnssecQueryResult performVerification(Question q, DnsQueryResult dnsQueryResult) throws IOException {
private DnssecQueryResult performVerification(DnsQueryResult dnsQueryResult) throws IOException {
if (dnsQueryResult == null) return null;

DnsMessage dnsMessage = dnsQueryResult.response;
@@ -172,7 +172,7 @@ private DnssecQueryResult performVerification(Question q, DnsQueryResult dnsQuer
}

// Verify all DNSKEYs as if it was a SEP. If we find a single SEP we are safe.
Set<DnssecUnverifiedReason> reasons = verifySecureEntryPoint(q, record);
Set<DnssecUnverifiedReason> reasons = verifySecureEntryPoint(record);
if (reasons.isEmpty()) {
sepSignatureValid = true;
} else {
@@ -272,7 +272,7 @@ private DnssecQueryResult performVerification(Question q, DnsQueryResult dnsQuer
return result;
}

private class VerifySignaturesResult {
private static class VerifySignaturesResult {
boolean sepSignatureRequired = false;
boolean sepSignaturePresent = false;
Set<DnssecUnverifiedReason> reasons = new HashSet<>();
@@ -401,7 +401,7 @@ private static boolean isParentOrSelf(String child, String parent) {
return result;
}

private Set<DnssecUnverifiedReason> verifySecureEntryPoint(Question q, final Record<DNSKEY> sepRecord) throws IOException {
private Set<DnssecUnverifiedReason> verifySecureEntryPoint(final Record<DNSKEY> sepRecord) throws IOException {
final DNSKEY dnskey = sepRecord.payloadData;

Set<DnssecUnverifiedReason> unverifiedReasons = new HashSet<>();
@@ -17,6 +17,7 @@
import org.junit.jupiter.api.Test;

import java.math.BigInteger;
import java.nio.charset.StandardCharsets;

import static org.junit.jupiter.api.Assertions.assertEquals;

@@ -47,6 +48,6 @@ public void testSha1nsec3Digest() {
}

private static String digestHexString(DigestCalculator digestCalculator, String in) {
return new BigInteger(1, digestCalculator.digest(in.getBytes())).toString(16);
return new BigInteger(1, digestCalculator.digest(in.getBytes(StandardCharsets.UTF_8))).toString(16);
}
}
@@ -16,7 +16,7 @@
import org.minidns.DnsClient;
import org.minidns.dnsmessage.Question;
import org.minidns.dnsqueryresult.DnsQueryResult;
import org.minidns.dnsmessage.DnsMessage.Builder;
import org.minidns.dnsmessage.DnsMessage;
import org.minidns.edns.Nsid;
import org.minidns.edns.Edns.OptionCode;
import org.minidns.iterative.IterativeDnsClient;
@@ -30,7 +30,7 @@
public static Nsid testNsidLRoot() {
DnsClient client = new DnsClient(null) {
@Override
protected Builder newQuestion(Builder message) {
protected DnsMessage.Builder newQuestion(DnsMessage.Builder message) {
message.getEdnsBuilder().addEdnsOption(Nsid.REQUEST);
return super.newQuestion(message);
}
@@ -15,6 +15,7 @@
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.ConsoleHandler;
@@ -25,14 +26,15 @@
import java.util.logging.LogRecord;
import java.util.logging.Logger;

@SuppressWarnings("DateFormatConstant")
public class MiniDnsJul {

private static final Logger LOGGER = Logger.getLogger(MiniDnsJul.class.getName());

private static final InputStream LOG_MANAGER_CONFIG = new ByteArrayInputStream((
// @formatter:off
"org.minidns.level=FINEST" + '\n'
).getBytes()
).getBytes(StandardCharsets.UTF_8)
);
// @formatter:on

@@ -342,6 +342,8 @@ private IpResultSet searchAdditional(DnsMessage message, DnsName name) {
case AAAA:
res.ipv6Addresses.add(inetAddressFromRecord(name.ace, (AAAA) record.payloadData));
break;
default:
break;
}
}
return res.build();
@@ -2,6 +2,6 @@ allprojects {
ext {
shortVersion = '0.4.0-alpha5'
isSnapshot = true
minidnsMinAndroidSdk = 9
minidnsMinAndroidSdk = 19
}
}

0 comments on commit a5c94b7

Please sign in to comment.
You can’t perform that action at this time.