Merge branch '2.0.x'

This commit is contained in:
Phillip Webb
2018-07-28 01:35:43 +01:00
360 changed files with 1434 additions and 1439 deletions

View File

@@ -116,8 +116,8 @@ public abstract class Launcher {
protected final Archive createArchive() throws Exception {
ProtectionDomain protectionDomain = getClass().getProtectionDomain();
CodeSource codeSource = protectionDomain.getCodeSource();
URI location = (codeSource != null ? codeSource.getLocation().toURI() : null);
String path = (location != null ? location.getSchemeSpecificPart() : null);
URI location = (codeSource != null) ? codeSource.getLocation().toURI() : null;
String path = (location != null) ? location.getSchemeSpecificPart() : null;
if (path == null) {
throw new IllegalStateException("Unable to determine code source archive");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,7 +38,7 @@ public class MainMethodRunner {
*/
public MainMethodRunner(String mainClass, String[] args) {
this.mainClassName = mainClass;
this.args = (args != null ? args.clone() : null);
this.args = (args != null) ? args.clone() : null;
}
public void run() throws Exception {

View File

@@ -434,9 +434,9 @@ public class PropertiesLauncher extends Launcher {
return SystemPropertyUtils.resolvePlaceholders(this.properties, value);
}
}
return (defaultValue != null
return (defaultValue != null)
? SystemPropertyUtils.resolvePlaceholders(this.properties, defaultValue)
: defaultValue);
: defaultValue;
}
@Override

View File

@@ -144,7 +144,7 @@ public class RandomAccessDataFile implements RandomAccessData {
@Override
public int read(byte[] b) throws IOException {
return read(b, 0, b != null ? b.length : 0);
return read(b, 0, (b != null) ? b.length : 0);
}
@Override
@@ -178,7 +178,7 @@ public class RandomAccessDataFile implements RandomAccessData {
@Override
public long skip(long n) throws IOException {
return (n <= 0 ? 0 : moveOn(cap(n)));
return (n <= 0) ? 0 : moveOn(cap(n));
}
/**

View File

@@ -124,24 +124,10 @@ final class AsciiBytes {
return new AsciiBytes(this.bytes, this.offset + beginIndex, length);
}
@Override
public String toString() {
if (this.string == null) {
if (this.length == 0) {
this.string = EMPTY_STRING;
}
else {
this.string = new String(this.bytes, this.offset, this.length,
StandardCharsets.UTF_8);
}
}
return this.string;
}
public boolean matches(CharSequence name, char suffix) {
int charIndex = 0;
int nameLen = name.length();
int totalLen = (nameLen + (suffix != 0 ? 1 : 0));
int totalLen = nameLen + ((suffix != 0) ? 1 : 0);
for (int i = this.offset; i < this.offset + this.length; i++) {
int b = this.bytes[i];
int remainingUtfBytes = getNumberOfUtfBytes(b) - 1;
@@ -178,30 +164,6 @@ final class AsciiBytes {
return 0;
}
@Override
public int hashCode() {
int hash = this.hash;
if (hash == 0 && this.bytes.length > 0) {
for (int i = this.offset; i < this.offset + this.length; i++) {
int b = this.bytes[i];
int remainingUtfBytes = getNumberOfUtfBytes(b) - 1;
b &= INITIAL_BYTE_BITMASK[remainingUtfBytes];
for (int j = 0; j < remainingUtfBytes; j++) {
b = (b << 6) + (this.bytes[++i] & SUBSEQUENT_BYTE_BITMASK);
}
if (b <= 0xFFFF) {
hash = 31 * hash + b;
}
else {
hash = 31 * hash + ((b >> 0xA) + 0xD7C0);
hash = 31 * hash + ((b & 0x3FF) + 0xDC00);
}
}
this.hash = hash;
}
return hash;
}
private int getNumberOfUtfBytes(int b) {
if ((b & 0x80) == 0) {
return 1;
@@ -236,6 +198,44 @@ final class AsciiBytes {
return false;
}
@Override
public int hashCode() {
int hash = this.hash;
if (hash == 0 && this.bytes.length > 0) {
for (int i = this.offset; i < this.offset + this.length; i++) {
int b = this.bytes[i];
int remainingUtfBytes = getNumberOfUtfBytes(b) - 1;
b &= INITIAL_BYTE_BITMASK[remainingUtfBytes];
for (int j = 0; j < remainingUtfBytes; j++) {
b = (b << 6) + (this.bytes[++i] & SUBSEQUENT_BYTE_BITMASK);
}
if (b <= 0xFFFF) {
hash = 31 * hash + b;
}
else {
hash = 31 * hash + ((b >> 0xA) + 0xD7C0);
hash = 31 * hash + ((b & 0x3FF) + 0xDC00);
}
}
this.hash = hash;
}
return hash;
}
@Override
public String toString() {
if (this.string == null) {
if (this.length == 0) {
this.string = EMPTY_STRING;
}
else {
this.string = new String(this.bytes, this.offset, this.length,
StandardCharsets.UTF_8);
}
}
return this.string;
}
static String toString(byte[] bytes) {
return new String(bytes, StandardCharsets.UTF_8);
}
@@ -250,7 +250,7 @@ final class AsciiBytes {
}
public static int hashCode(int hash, char suffix) {
return (suffix != 0 ? (31 * hash + suffix) : hash);
return (suffix != 0) ? (31 * hash + suffix) : hash;
}
}

View File

@@ -44,7 +44,7 @@ class CentralDirectoryParser {
* Parse the source data, triggering {@link CentralDirectoryVisitor visitors}.
* @param data the source data
* @param skipPrefixBytes if prefix bytes should be skipped
* @return The actual archive data without any prefix bytes
* @return the actual archive data without any prefix bytes
* @throws IOException on error
*/
public RandomAccessData parse(RandomAccessData data, boolean skipPrefixBytes)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -250,7 +250,7 @@ public class Handler extends URLStreamHandler {
}
private int hashCode(String protocol, String file) {
int result = (protocol != null ? protocol.hashCode() : 0);
int result = (protocol != null) ? protocol.hashCode() : 0;
int separatorIndex = file.indexOf(SEPARATOR);
if (separatorIndex == -1) {
return result + file.hashCode();
@@ -319,7 +319,7 @@ public class Handler extends URLStreamHandler {
String path = name.substring(FILE_PROTOCOL.length());
File file = new File(URLDecoder.decode(path, "UTF-8"));
Map<File, JarFile> cache = rootFileCache.get();
JarFile result = (cache != null ? cache.get(file) : null);
JarFile result = (cache != null) ? cache.get(file) : null;
if (result == null) {
result = new JarFile(file);
addToRootFileCache(file, result);

View File

@@ -77,7 +77,7 @@ class JarEntry extends java.util.jar.JarEntry implements FileHeader {
@Override
public Attributes getAttributes() throws IOException {
Manifest manifest = this.jarFile.getManifest();
return (manifest != null ? manifest.getAttributes(getName()) : null);
return (manifest != null) ? manifest.getAttributes(getName()) : null;
}
@Override

View File

@@ -120,7 +120,7 @@ public class JarFile extends java.util.jar.JarFile {
parser.addVisitor(centralDirectoryVisitor());
this.data = parser.parse(data, filter == null);
this.type = type;
this.manifestSupplier = (manifestSupplier != null ? manifestSupplier : () -> {
this.manifestSupplier = (manifestSupplier != null) ? manifestSupplier : () -> {
try (InputStream inputStream = getInputStream(MANIFEST_NAME)) {
if (inputStream == null) {
return null;
@@ -130,7 +130,7 @@ public class JarFile extends java.util.jar.JarFile {
catch (IOException ex) {
throw new RuntimeException(ex);
}
});
};
}
private CentralDirectoryVisitor centralDirectoryVisitor() {
@@ -168,7 +168,7 @@ public class JarFile extends java.util.jar.JarFile {
@Override
public Manifest getManifest() throws IOException {
Manifest manifest = (this.manifest != null ? this.manifest.get() : null);
Manifest manifest = (this.manifest != null) ? this.manifest.get() : null;
if (manifest == null) {
try {
manifest = this.manifestSupplier.get();
@@ -218,11 +218,11 @@ public class JarFile extends java.util.jar.JarFile {
}
@Override
public synchronized InputStream getInputStream(ZipEntry ze) throws IOException {
if (ze instanceof JarEntry) {
return this.entries.getInputStream((JarEntry) ze);
public synchronized InputStream getInputStream(ZipEntry entry) throws IOException {
if (entry instanceof JarEntry) {
return this.entries.getInputStream((JarEntry) entry);
}
return getInputStream(ze != null ? ze.getName() : null);
return getInputStream((entry != null) ? entry.getName() : null);
}
InputStream getInputStream(String name) throws IOException {

View File

@@ -243,10 +243,10 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
boolean cacheEntry) {
try {
FileHeader cached = this.entriesCache.get(index);
FileHeader entry = (cached != null ? cached
FileHeader entry = (cached != null) ? cached
: CentralDirectoryFileHeader.fromRandomAccessData(
this.centralDirectoryData,
this.centralDirectoryOffsets[index], this.filter));
this.centralDirectoryOffsets[index], this.filter);
if (CentralDirectoryFileHeader.class.equals(entry.getClass())
&& type.equals(JarEntry.class)) {
entry = new JarEntry(this.jarFile, (CentralDirectoryFileHeader) entry);
@@ -277,7 +277,7 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
}
private AsciiBytes applyFilter(AsciiBytes name) {
return (this.filter != null ? this.filter.apply(name) : name);
return (this.filter != null) ? this.filter.apply(name) : name;
}
/**

View File

@@ -204,7 +204,7 @@ final class JarURLConnection extends java.net.JarURLConnection {
return this.jarFile.size();
}
JarEntry entry = getJarEntry();
return (entry != null ? (int) entry.getSize() : -1);
return (entry != null) ? (int) entry.getSize() : -1;
}
catch (IOException ex) {
return -1;
@@ -219,7 +219,7 @@ final class JarURLConnection extends java.net.JarURLConnection {
@Override
public String getContentType() {
return (this.jarEntryName != null ? this.jarEntryName.getContentType() : null);
return (this.jarEntryName != null) ? this.jarEntryName.getContentType() : null;
}
@Override
@@ -241,7 +241,7 @@ final class JarURLConnection extends java.net.JarURLConnection {
}
try {
JarEntry entry = getJarEntry();
return (entry != null ? entry.getTime() : 0);
return (entry != null) ? entry.getTime() : 0;
}
catch (IOException ex) {
return 0;
@@ -387,8 +387,8 @@ final class JarURLConnection extends java.net.JarURLConnection {
private String deduceContentType() {
// Guess the content type, don't bother with streams as mark is not supported
String type = (isEmpty() ? "x-java/jar" : null);
type = (type != null ? type : guessContentTypeFromName(toString()));
type = (type != null ? type : "content/unknown");
type = (type != null) ? type : guessContentTypeFromName(toString());
type = (type != null) ? type : "content/unknown";
return type;
}

View File

@@ -36,7 +36,7 @@ final class StringSequence implements CharSequence {
private int hash;
StringSequence(String source) {
this(source, 0, source != null ? source.length() : -1);
this(source, 0, (source != null) ? source.length() : -1);
}
StringSequence(String source, int start, int end) {
@@ -106,23 +106,6 @@ final class StringSequence implements CharSequence {
return subSequence(offset, offset + prefix.length()).equals(prefix);
}
@Override
public String toString() {
return this.source.substring(this.start, this.end);
}
@Override
public int hashCode() {
int hash = this.hash;
if (hash == 0 && length() > 0) {
for (int i = this.start; i < this.end; i++) {
hash = 31 * hash + this.source.charAt(i);
}
this.hash = hash;
}
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
@@ -146,4 +129,21 @@ final class StringSequence implements CharSequence {
return true;
}
@Override
public int hashCode() {
int hash = this.hash;
if (hash == 0 && length() > 0) {
for (int i = this.start; i < this.end; i++) {
hash = 31 * hash + this.source.charAt(i);
}
this.hash = hash;
}
return hash;
}
@Override
public String toString() {
return this.source.substring(this.start, this.end);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -74,8 +74,8 @@ class ZipInflaterInputStream extends InflaterInputStream {
private static int getInflaterBufferSize(long size) {
size += 2; // inflater likes some space
size = (size > 65536 ? 8192 : size);
size = (size <= 0 ? 4096 : size);
size = (size > 65536) ? 8192 : size;
size = (size <= 0) ? 4096 : size;
return (int) size;
}

View File

@@ -155,7 +155,7 @@ public abstract class SystemPropertyUtils {
if (propVal != null) {
return propVal;
}
return (properties != null ? properties.getProperty(placeholderName) : null);
return (properties != null) ? properties.getProperty(placeholderName) : null;
}
public static String getProperty(String key) {