@@ -683,11 +683,7 @@ public class ComponentHelper { | |||||
String name = def.getName(); | String name = def.getName(); | ||||
List<AntTypeDefinition> list = null; | List<AntTypeDefinition> list = null; | ||||
synchronized (restrictedDefinitions) { | synchronized (restrictedDefinitions) { | ||||
list = restrictedDefinitions.get(name); | |||||
if (list == null) { | |||||
list = new ArrayList<>(); | |||||
restrictedDefinitions.put(name, list); | |||||
} | |||||
list = restrictedDefinitions.computeIfAbsent(name, k -> new ArrayList<>()); | |||||
} | } | ||||
// Check if the classname is already present and remove it | // Check if the classname is already present and remove it | ||||
// if it is | // if it is | ||||
@@ -1028,8 +1028,7 @@ public final class IntrospectionHelper { | |||||
final String attrName) { | final String attrName) { | ||||
// use wrappers for primitive classes, e.g. int and | // use wrappers for primitive classes, e.g. int and | ||||
// Integer are treated identically | // Integer are treated identically | ||||
final Class<?> reflectedArg = PRIMITIVE_TYPE_MAP.containsKey(arg) | |||||
? PRIMITIVE_TYPE_MAP.get(arg) : arg; | |||||
final Class<?> reflectedArg = PRIMITIVE_TYPE_MAP.getOrDefault(arg, arg); | |||||
// Object.class - it gets handled differently by AttributeSetter | // Object.class - it gets handled differently by AttributeSetter | ||||
if (java.lang.Object.class == reflectedArg) { | if (java.lang.Object.class == reflectedArg) { | ||||
@@ -406,11 +406,7 @@ public class Main implements AntMain { | |||||
for (final ArgumentProcessor processor : processorRegistry.getProcessors()) { | for (final ArgumentProcessor processor : processorRegistry.getProcessors()) { | ||||
final int newI = processor.readArguments(args, i); | final int newI = processor.readArguments(args, i); | ||||
if (newI != -1) { | if (newI != -1) { | ||||
List<String> extraArgs = extraArguments.get(processor.getClass()); | |||||
if (extraArgs == null) { | |||||
extraArgs = new ArrayList<>(); | |||||
extraArguments.put(processor.getClass(), extraArgs); | |||||
} | |||||
List<String> extraArgs = extraArguments.computeIfAbsent(processor.getClass(), k -> new ArrayList<>()); | |||||
for (; i < newI && i < args.length; i++) { | for (; i < newI && i < args.length; i++) { | ||||
extraArgs.add(args[i]); | extraArgs.add(args[i]); | ||||
} | } | ||||
@@ -179,12 +179,7 @@ public class Project implements ResourceFactory { | |||||
/** for each thread, record whether it is currently executing | /** for each thread, record whether it is currently executing | ||||
messageLogged */ | messageLogged */ | ||||
private final ThreadLocal<Boolean> isLoggingMessage = new ThreadLocal<Boolean>() { | |||||
@Override | |||||
protected Boolean initialValue() { | |||||
return Boolean.FALSE; | |||||
} | |||||
}; | |||||
private final ThreadLocal<Boolean> isLoggingMessage = ThreadLocal.withInitial(() -> Boolean.FALSE); | |||||
/** | /** | ||||
* The Ant core classloader--may be <code>null</code> if using | * The Ant core classloader--may be <code>null</code> if using | ||||
@@ -202,11 +202,7 @@ public class ProjectHelper { | |||||
targetPrefix.set(prefix); | targetPrefix.set(prefix); | ||||
} | } | ||||
private static final ThreadLocal<String> prefixSeparator = new ThreadLocal<String>() { | |||||
protected String initialValue() { | |||||
return "."; | |||||
} | |||||
}; | |||||
private static final ThreadLocal<String> prefixSeparator = ThreadLocal.withInitial(() -> "."); | |||||
/** | /** | ||||
* The separator between the prefix and the target name. | * The separator between the prefix and the target name. | ||||
@@ -230,11 +226,7 @@ public class ProjectHelper { | |||||
prefixSeparator.set(sep); | prefixSeparator.set(sep); | ||||
} | } | ||||
private static final ThreadLocal<Boolean> inIncludeMode = new ThreadLocal<Boolean>() { | |||||
protected Boolean initialValue() { | |||||
return Boolean.FALSE; | |||||
} | |||||
}; | |||||
private static final ThreadLocal<Boolean> inIncludeMode = ThreadLocal.withInitial(() -> Boolean.FALSE); | |||||
/** | /** | ||||
* Whether the current file should be read in include as opposed | * Whether the current file should be read in include as opposed | ||||
@@ -207,11 +207,7 @@ public class XmlLogger implements BuildLogger { | |||||
* @return the stack of timed elements for the current thread | * @return the stack of timed elements for the current thread | ||||
*/ | */ | ||||
private Stack<TimedElement> getStack() { | private Stack<TimedElement> getStack() { | ||||
Stack<TimedElement> threadStack = threadStacks.get(Thread.currentThread()); | |||||
if (threadStack == null) { | |||||
threadStack = new Stack<>(); | |||||
threadStacks.put(Thread.currentThread(), threadStack); | |||||
} | |||||
Stack<TimedElement> threadStack = threadStacks.computeIfAbsent(Thread.currentThread(), k -> new Stack<>()); | |||||
/* For debugging purposes uncomment: | /* For debugging purposes uncomment: | ||||
org.w3c.dom.Comment s = doc.createComment("stack=" + threadStack); | org.w3c.dom.Comment s = doc.createComment("stack=" + threadStack); | ||||
buildElement.element.appendChild(s); | buildElement.element.appendChild(s); | ||||
@@ -362,11 +362,7 @@ public class AntXMLContext { | |||||
* @param uri a namespace uri | * @param uri a namespace uri | ||||
*/ | */ | ||||
public void startPrefixMapping(String prefix, String uri) { | public void startPrefixMapping(String prefix, String uri) { | ||||
List<String> list = prefixMapping.get(prefix); | |||||
if (list == null) { | |||||
list = new ArrayList<>(); | |||||
prefixMapping.put(prefix, list); | |||||
} | |||||
List<String> list = prefixMapping.computeIfAbsent(prefix, k -> new ArrayList<>()); | |||||
list.add(uri); | list.add(uri); | ||||
} | } | ||||
@@ -1015,11 +1015,7 @@ public class Copy extends Task { | |||||
private static void add(File baseDir, final String[] names, final Map<File, List<String>> m) { | private static void add(File baseDir, final String[] names, final Map<File, List<String>> m) { | ||||
if (names != null) { | if (names != null) { | ||||
baseDir = getKeyFile(baseDir); | baseDir = getKeyFile(baseDir); | ||||
List<String> l = m.get(baseDir); | |||||
if (l == null) { | |||||
l = new ArrayList<>(names.length); | |||||
m.put(baseDir, l); | |||||
} | |||||
List<String> l = m.computeIfAbsent(baseDir, k -> new ArrayList<>(names.length)); | |||||
l.addAll(Arrays.asList(names)); | l.addAll(Arrays.asList(names)); | ||||
} | } | ||||
} | } | ||||
@@ -54,12 +54,7 @@ public abstract class Definer extends DefBase { | |||||
*/ | */ | ||||
private static final String ANTLIB_XML = "/antlib.xml"; | private static final String ANTLIB_XML = "/antlib.xml"; | ||||
private static final ThreadLocal<Map<URL, Location>> RESOURCE_STACK = new ThreadLocal<Map<URL, Location>>() { | |||||
@Override | |||||
protected Map<URL, Location> initialValue() { | |||||
return new HashMap<>(); | |||||
} | |||||
}; | |||||
private static final ThreadLocal<Map<URL, Location>> RESOURCE_STACK = ThreadLocal.withInitial(HashMap::new); | |||||
private String name; | private String name; | ||||
private String classname; | private String classname; | ||||
@@ -1695,11 +1695,7 @@ public class Javac extends MatchingTask { | |||||
final File moduleSourceRoot = pathInModule == null ? | final File moduleSourceRoot = pathInModule == null ? | ||||
module : | module : | ||||
new File(module, pathInModule); | new File(module, pathInModule); | ||||
Collection<File> moduleRoots = collector.get(moduleName); | |||||
if (moduleRoots == null) { | |||||
moduleRoots = new ArrayList<>(); | |||||
collector.put(moduleName, moduleRoots); | |||||
} | |||||
Collection<File> moduleRoots = collector.computeIfAbsent(moduleName, k -> new ArrayList<>()); | |||||
moduleRoots.add(moduleSourceRoot); | moduleRoots.add(moduleSourceRoot); | ||||
} | } | ||||
} | } | ||||
@@ -605,11 +605,7 @@ public class Tar extends MatchingTask { | |||||
base = Copy.NULL_FILE_PLACEHOLDER; | base = Copy.NULL_FILE_PLACEHOLDER; | ||||
} | } | ||||
basedirs.add(base); | basedirs.add(base); | ||||
List<String> files = basedirToFilesMap.get(base); | |||||
if (files == null) { | |||||
files = new Vector<>(); | |||||
basedirToFilesMap.put(base, files); | |||||
} | |||||
List<String> files = basedirToFilesMap.computeIfAbsent(base, k -> new Vector<>()); | |||||
if (base == Copy.NULL_FILE_PLACEHOLDER) { | if (base == Copy.NULL_FILE_PLACEHOLDER) { | ||||
files.add(r.getFile().getAbsolutePath()); | files.add(r.getFile().getAbsolutePath()); | ||||
} else { | } else { | ||||
@@ -1296,12 +1296,7 @@ public class Zip extends MatchingTask { | |||||
* to move the withEmpty behavior checks (since either would break | * to move the withEmpty behavior checks (since either would break | ||||
* subclasses in several ways). | * subclasses in several ways). | ||||
*/ | */ | ||||
private static final ThreadLocal<Boolean> HAVE_NON_FILE_SET_RESOURCES_TO_ADD = new ThreadLocal<Boolean>() { | |||||
@Override | |||||
protected Boolean initialValue() { | |||||
return Boolean.FALSE; | |||||
} | |||||
}; | |||||
private static final ThreadLocal<Boolean> HAVE_NON_FILE_SET_RESOURCES_TO_ADD = ThreadLocal.withInitial(() -> Boolean.FALSE); | |||||
/** | /** | ||||
* Collect the resources that are newer than the corresponding | * Collect the resources that are newer than the corresponding | ||||
@@ -263,9 +263,8 @@ class ChangeLogParser { | |||||
* Utility method that saves the current entry. | * Utility method that saves the current entry. | ||||
*/ | */ | ||||
private void saveEntry() { | private void saveEntry() { | ||||
entries.computeIfAbsent(date + author + comment, k -> { | |||||
return new CVSEntry(parseDate(date), author, comment); | |||||
}).addFile(file, revision, previousRevision); | |||||
entries.computeIfAbsent(date + author + comment, | |||||
k -> new CVSEntry(parseDate(date), author, comment)).addFile(file, revision, previousRevision); | |||||
} | } | ||||
/** | /** | ||||
@@ -458,9 +458,7 @@ public class Translate extends MatchingTask { | |||||
} | } | ||||
if (key.length() > 0) { | if (key.length() > 0) { | ||||
//Has key already been loaded into resourceMap? | //Has key already been loaded into resourceMap? | ||||
if (resourceMap.get(key) == null) { | |||||
resourceMap.put(key, value); | |||||
} | |||||
resourceMap.putIfAbsent(key, value); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -98,12 +98,7 @@ public final class DateUtils { | |||||
* @since Ant 1.10.2 | * @since Ant 1.10.2 | ||||
*/ | */ | ||||
public static final ThreadLocal<DateFormat> EN_US_DATE_FORMAT_MIN = | public static final ThreadLocal<DateFormat> EN_US_DATE_FORMAT_MIN = | ||||
new ThreadLocal<DateFormat>() { | |||||
@Override | |||||
protected DateFormat initialValue() { | |||||
return new SimpleDateFormat("MM/dd/yyyy hh:mm a", Locale.US); | |||||
} | |||||
}; | |||||
ThreadLocal.withInitial(() -> new SimpleDateFormat("MM/dd/yyyy hh:mm a", Locale.US)); | |||||
/** | /** | ||||
* Provides a thread-local US-style date format. Exactly as used by | * Provides a thread-local US-style date format. Exactly as used by | ||||
@@ -112,12 +107,7 @@ public final class DateUtils { | |||||
* @since Ant 1.10.2 | * @since Ant 1.10.2 | ||||
*/ | */ | ||||
public static final ThreadLocal<DateFormat> EN_US_DATE_FORMAT_SEC = | public static final ThreadLocal<DateFormat> EN_US_DATE_FORMAT_SEC = | ||||
new ThreadLocal<DateFormat>() { | |||||
@Override | |||||
protected DateFormat initialValue() { | |||||
return new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a", Locale.US); | |||||
} | |||||
}; | |||||
ThreadLocal.withInitial(() -> new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a", Locale.US)); | |||||
static { | static { | ||||
MINUTE_SECONDS.setFormat(0, MINUTES_FORMAT); | MINUTE_SECONDS.setFormat(0, MINUTES_FORMAT); | ||||
@@ -329,12 +319,10 @@ public final class DateUtils { | |||||
} | } | ||||
final private static ThreadLocal<DateFormat> iso8601WithTimeZone = | final private static ThreadLocal<DateFormat> iso8601WithTimeZone = | ||||
new ThreadLocal<DateFormat>() { | |||||
@Override protected DateFormat initialValue() { | |||||
ThreadLocal.withInitial(() -> { | |||||
// An arbitrary easy-to-read format to normalize to. | // An arbitrary easy-to-read format to normalize to. | ||||
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z"); | return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z"); | ||||
} | |||||
}; | |||||
}); | |||||
final private static Pattern iso8601normalizer = Pattern.compile( | final private static Pattern iso8601normalizer = Pattern.compile( | ||||
"^(\\d{4,}-\\d{2}-\\d{2})[Tt ]" + // yyyy-MM-dd | "^(\\d{4,}-\\d{2}-\\d{2})[Tt ]" + // yyyy-MM-dd | ||||
"(\\d{2}:\\d{2}(:\\d{2}(\\.\\d{3})?)?) ?" + // HH:mm:ss.SSS | "(\\d{2}:\\d{2}(:\\d{2}(\\.\\d{3})?)?) ?" + // HH:mm:ss.SSS | ||||
@@ -889,11 +889,7 @@ public class ZipFile implements Closeable { | |||||
} | } | ||||
final String name = ze.getName(); | final String name = ze.getName(); | ||||
LinkedList<ZipEntry> entriesOfThatName = nameMap.get(name); | |||||
if (entriesOfThatName == null) { | |||||
entriesOfThatName = new LinkedList<>(); | |||||
nameMap.put(name, entriesOfThatName); | |||||
} | |||||
LinkedList<ZipEntry> entriesOfThatName = nameMap.computeIfAbsent(name, k -> new LinkedList<>()); | |||||
entriesOfThatName.addLast(ze); | entriesOfThatName.addLast(ze); | ||||
} | } | ||||
} | } | ||||