You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by mb...@apache.org on 2017/04/13 15:16:32 UTC

[32/34] ant git commit: java 5-8

http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/UnknownElement.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/UnknownElement.java b/src/main/org/apache/tools/ant/UnknownElement.java
index 15770c2..7a4a60a 100644
--- a/src/main/org/apache/tools/ant/UnknownElement.java
+++ b/src/main/org/apache/tools/ant/UnknownElement.java
@@ -24,6 +24,7 @@ import java.util.Enumeration;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 
 import org.apache.tools.ant.taskdefs.PreSetDef;
 
@@ -234,10 +235,8 @@ public class UnknownElement extends Task {
         throws IOException {
         if (realThing instanceof Task) {
             return ((Task) realThing).handleInput(buffer, offset, length);
-        } else {
-            return super.handleInput(buffer, offset, length);
         }
-
+        return super.handleInput(buffer, offset, length);
     }
 
     /**
@@ -311,7 +310,7 @@ public class UnknownElement extends Task {
      */
     public void addChild(UnknownElement child) {
         if (children == null) {
-            children = new ArrayList<UnknownElement>();
+            children = new ArrayList<>();
         }
         children.add(child);
     }
@@ -341,7 +340,6 @@ public class UnknownElement extends Task {
         Class<?> parentClass = parent.getClass();
         IntrospectionHelper ih = IntrospectionHelper.getHelper(getProject(), parentClass);
 
-
         if (children != null) {
             Iterator<UnknownElement> it = children.iterator();
             for (int i = 0; it.hasNext(); i++) {
@@ -400,7 +398,7 @@ public class UnknownElement extends Task {
         // Do the runtime
         getWrapper().applyPreSet(u.getWrapper());
         if (u.children != null) {
-            List<UnknownElement> newChildren = new ArrayList<UnknownElement>();
+            List<UnknownElement> newChildren = new ArrayList<>();
             newChildren.addAll(u.children);
             if (children != null) {
                 newChildren.addAll(children);
@@ -506,7 +504,6 @@ public class UnknownElement extends Task {
      * @return the name to use in logging messages.
      */
     public String getTaskName() {
-        //return elementName;
         return realThing == null
             || !(realThing instanceof Task) ? super.getTaskName()
                                             : ((Task) realThing).getTaskName();
@@ -612,7 +609,7 @@ public class UnknownElement extends Task {
         }
         UnknownElement other = (UnknownElement) obj;
         // Are the names the same ?
-        if (!equalsString(elementName, other.elementName)) {
+        if (!Objects.equals(elementName, other.elementName)) {
             return false;
         }
         if (!namespace.equals(other.namespace)) {
@@ -637,7 +634,7 @@ public class UnknownElement extends Task {
         // Are the sub elements the same ?
         final int childrenSize = children == null ? 0 : children.size();
         if (childrenSize == 0) {
-            return other.children == null || other.children.size() == 0;
+            return other.children == null || other.children.isEmpty();
         }
         if (other.children == null) {
             return false;
@@ -655,10 +652,6 @@ public class UnknownElement extends Task {
         return true;
     }
 
-    private static boolean equalsString(String a, String b) {
-        return (a == null) ? (b == null) : a.equals(b);
-    }
-
     /**
      * Make a copy of the unknown element and set it in the new project.
      * @param newProject the project to create the UE in.

http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/XmlLogger.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/XmlLogger.java b/src/main/org/apache/tools/ant/XmlLogger.java
index 086123e..3a9848e 100644
--- a/src/main/org/apache/tools/ant/XmlLogger.java
+++ b/src/main/org/apache/tools/ant/XmlLogger.java
@@ -32,7 +32,6 @@ import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 
 import org.apache.tools.ant.util.DOMElementWriter;
-import org.apache.tools.ant.util.FileUtils;
 import org.apache.tools.ant.util.StringUtils;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -109,16 +108,16 @@ public class XmlLogger implements BuildLogger {
     private Document doc = builder.newDocument();
 
     /** Mapping for when tasks started (Task to TimedElement). */
-    private Hashtable<Task, TimedElement> tasks = new Hashtable<Task, TimedElement>();
+    private Hashtable<Task, TimedElement> tasks = new Hashtable<>();
 
     /** Mapping for when targets started (Target to TimedElement). */
-    private Hashtable<Target, TimedElement> targets = new Hashtable<Target, XmlLogger.TimedElement>();
+    private Hashtable<Target, TimedElement> targets = new Hashtable<>();
 
     /**
      * Mapping of threads to stacks of elements
      * (Thread to Stack of TimedElement).
      */
-    private Hashtable<Thread, Stack<TimedElement>> threadStacks = new Hashtable<Thread, Stack<TimedElement>>();
+    private Hashtable<Thread, Stack<TimedElement>> threadStacks = new Hashtable<>();
 
     /**
      * When the build started.
@@ -134,23 +133,20 @@ public class XmlLogger implements BuildLogger {
         private long startTime;
         /** Element created at the start time. */
         private Element element;
+
+        @Override
         public String toString() {
             return element.getTagName() + ":" + element.getAttribute("name");
         }
     }
 
     /**
-     *  Constructs a new BuildListener that logs build events to an XML file.
-     */
-    public XmlLogger() {
-    }
-
-    /**
      * Fired when the build starts, this builds the top-level element for the
      * document and remembers the time of the start of the build.
      *
      * @param event Ignored.
      */
+    @Override
     public void buildStarted(BuildEvent event) {
         buildElement = new TimedElement();
         buildElement.startTime = System.currentTimeMillis();
@@ -164,6 +160,7 @@ public class XmlLogger implements BuildLogger {
      * @param event An event with any relevant extra information.
      *              Will not be <code>null</code>.
      */
+    @Override
     public void buildFinished(BuildEvent event) {
         long totalTime = System.currentTimeMillis() - buildElement.startTime;
         buildElement.element.setAttribute(TIME_ATTR, DefaultLogger.formatTime(totalTime));
@@ -180,25 +177,19 @@ public class XmlLogger implements BuildLogger {
         }
         String outFilename = getProperty(event, "XmlLogger.file", "log.xml");
         String xslUri = getProperty(event, "ant.XmlLogger.stylesheet.uri", "log.xsl");
-        Writer out = null;
-        try {
-            // specify output in UTF8 otherwise accented characters will blow
-            // up everything
-            OutputStream stream = outStream;
-            if (stream == null) {
-                stream = Files.newOutputStream(Paths.get(outFilename));
-            }
-            out = new OutputStreamWriter(stream, "UTF8");
+        
+        try (OutputStream stream =
+            outStream == null ? Files.newOutputStream(Paths.get(outFilename)) : outStream;
+                Writer out = new OutputStreamWriter(stream, "UTF8")) {
             out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
             if (xslUri.length() > 0) {
-                out.write("<?xml-stylesheet type=\"text/xsl\" href=\"" + xslUri + "\"?>\n\n");
+                out.write("<?xml-stylesheet type=\"text/xsl\" href=\"" + xslUri
+                    + "\"?>\n\n");
             }
             new DOMElementWriter().write(buildElement.element, out, 0, "\t");
             out.flush();
         } catch (IOException exc) {
             throw new BuildException("Unable to write log file", exc);
-        } finally {
-            FileUtils.close(out);
         }
         buildElement = null;
     }
@@ -218,7 +209,7 @@ public class XmlLogger implements BuildLogger {
     private Stack<TimedElement> getStack() {
         Stack<TimedElement> threadStack = threadStacks.get(Thread.currentThread());
         if (threadStack == null) {
-            threadStack = new Stack<TimedElement>();
+            threadStack = new Stack<>();
             threadStacks.put(Thread.currentThread(), threadStack);
         }
         /* For debugging purposes uncomment:
@@ -236,6 +227,7 @@ public class XmlLogger implements BuildLogger {
      * @param event An event with any relevant extra information.
      *              Will not be <code>null</code>.
      */
+    @Override
     public void targetStarted(BuildEvent event) {
         Target target = event.getTarget();
         TimedElement targetElement = new TimedElement();
@@ -253,6 +245,7 @@ public class XmlLogger implements BuildLogger {
      * @param event An event with any relevant extra information.
      *              Will not be <code>null</code>.
      */
+    @Override
     public void targetFinished(BuildEvent event) {
         Target target = event.getTarget();
         TimedElement targetElement = targets.get(target);
@@ -290,6 +283,7 @@ public class XmlLogger implements BuildLogger {
      * @param event An event with any relevant extra information.
      *              Will not be <code>null</code>.
      */
+    @Override
     public void taskStarted(BuildEvent event) {
         TimedElement taskElement = new TimedElement();
         taskElement.startTime = System.currentTimeMillis();
@@ -313,6 +307,7 @@ public class XmlLogger implements BuildLogger {
      * @param event An event with any relevant extra information.
      *              Will not be <code>null</code>.
      */
+    @Override
     public void taskFinished(BuildEvent event) {
         Task task = event.getTask();
         TimedElement taskElement = tasks.get(task);
@@ -355,10 +350,9 @@ public class XmlLogger implements BuildLogger {
         }
         for (Enumeration<Task> e = tasks.keys(); e.hasMoreElements();) {
             Task key = e.nextElement();
-            if (key instanceof UnknownElement) {
-                if (((UnknownElement) key).getTask() == task) {
-                    return tasks.get(key);
-                }
+            if (key instanceof UnknownElement
+                && ((UnknownElement) key).getTask() == task) {
+                return tasks.get(key);
             }
         }
         return null;
@@ -372,6 +366,7 @@ public class XmlLogger implements BuildLogger {
      * @param event An event with any relevant extra information.
      *              Will not be <code>null</code>.
      */
+    @Override
     public void messageLogged(BuildEvent event) {
         int priority = event.getPriority();
         if (priority > msgOutputLevel) {
@@ -379,7 +374,7 @@ public class XmlLogger implements BuildLogger {
         }
         Element messageElement = doc.createElement(MESSAGE_TAG);
 
-        String name = "debug";
+        String name;
         switch (priority) {
             case Project.MSG_ERR:
                 name = "error";
@@ -433,6 +428,7 @@ public class XmlLogger implements BuildLogger {
      *        see {@link org.apache.tools.ant.Project#MSG_ERR Project}
      *        class for level definitions
      */
+    @Override
     public void setMessageOutputLevel(int level) {
         msgOutputLevel = level;
     }
@@ -443,6 +439,7 @@ public class XmlLogger implements BuildLogger {
      *
      * @param output the output PrintStream.
      */
+    @Override
     public void setOutputPrintStream(PrintStream output) {
         this.outStream = new PrintStream(output, true);
     }
@@ -453,6 +450,7 @@ public class XmlLogger implements BuildLogger {
      * @param emacsMode true if logger should produce emacs compatible
      *        output
      */
+    @Override
     public void setEmacsMode(boolean emacsMode) {
     }
 
@@ -463,6 +461,7 @@ public class XmlLogger implements BuildLogger {
      *
      * @param err the stream we are going to ignore.
      */
+    @Override
     public void setErrorPrintStream(PrintStream err) {
     }
 

http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/attribute/BaseIfAttribute.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/attribute/BaseIfAttribute.java b/src/main/org/apache/tools/ant/attribute/BaseIfAttribute.java
index c2ec08a..f0b03d9 100644
--- a/src/main/org/apache/tools/ant/attribute/BaseIfAttribute.java
+++ b/src/main/org/apache/tools/ant/attribute/BaseIfAttribute.java
@@ -19,6 +19,7 @@
 package org.apache.tools.ant.attribute;
 
 import java.util.HashMap;
+import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.Map;
 
@@ -67,18 +68,19 @@ public abstract class BaseIfAttribute
      * @param el the element this attribute is in.
      * @return a map of attributes.
      */
-    protected Map getParams(UnknownElement el) {
-        Map ret = new HashMap();
+    protected Map<String, String> getParams(UnknownElement el) {
+        Map<String, String> ret = new HashMap<>();
         RuntimeConfigurable rc = el.getWrapper();
-        Map attributes = rc.getAttributeMap(); // This does a copy!
-        for (Iterator i = attributes.entrySet().iterator(); i.hasNext();) {
-            Map.Entry entry = (Map.Entry) i.next();
-            String key = (String) entry.getKey();
+        Hashtable<String, Object> attributes = rc.getAttributeMap(); // This does a copy!
+        for (Iterator<Map.Entry<String, Object>> i =
+            attributes.entrySet().iterator(); i.hasNext();) {
+            Map.Entry<String, Object> entry = i.next();
+            String key = entry.getKey();
             String value = (String) entry.getValue();
             if (key.startsWith("ant-attribute:param")) {
                 int pos = key.lastIndexOf(':');
                 ret.put(key.substring(pos + 1),
-                        el.getProject().replaceProperties(value));
+                    el.getProject().replaceProperties(value));
             }
         }
         return ret;

http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/dispatch/DispatchTask.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/dispatch/DispatchTask.java b/src/main/org/apache/tools/ant/dispatch/DispatchTask.java
index a848ed1..66eb96f 100644
--- a/src/main/org/apache/tools/ant/dispatch/DispatchTask.java
+++ b/src/main/org/apache/tools/ant/dispatch/DispatchTask.java
@@ -37,6 +37,7 @@ public abstract class DispatchTask extends Task implements Dispatchable {
      * Get the action parameter name.
      * @return the <code>String</code> "action" by default (can be overridden).
      */
+    @Override
     public String getActionParameterName() {
         return "action";
     }

http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/dispatch/DispatchUtils.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/dispatch/DispatchUtils.java b/src/main/org/apache/tools/ant/dispatch/DispatchUtils.java
index 1a7c1f9..852a920 100644
--- a/src/main/org/apache/tools/ant/dispatch/DispatchUtils.java
+++ b/src/main/org/apache/tools/ant/dispatch/DispatchUtils.java
@@ -98,12 +98,12 @@ public class DispatchUtils {
                 }
             } else {
                 Method executeM = null;
-                executeM = task.getClass().getMethod(methodName, new Class[0]);
+                executeM = task.getClass().getMethod(methodName);
                 if (executeM == null) {
                     throw new BuildException("No public " + methodName + "() in "
                         + task.getClass());
                 }
-                executeM.invoke(task, (Object[]) null);
+                executeM.invoke(task);
                 if (task instanceof UnknownElement) {
                     ((UnknownElement) task).setRealThing(null);
                 }

http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/filters/util/ChainReaderHelper.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/filters/util/ChainReaderHelper.java b/src/main/org/apache/tools/ant/filters/util/ChainReaderHelper.java
index f176c33..9ad2f3d 100644
--- a/src/main/org/apache/tools/ant/filters/util/ChainReaderHelper.java
+++ b/src/main/org/apache/tools/ant/filters/util/ChainReaderHelper.java
@@ -23,9 +23,13 @@ import java.io.Reader;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
-import java.util.Iterator;
+import java.util.Collection;
 import java.util.List;
+import java.util.Optional;
 import java.util.Vector;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import org.apache.tools.ant.AntClassLoader;
 import org.apache.tools.ant.BuildException;
@@ -34,7 +38,6 @@ import org.apache.tools.ant.filters.BaseFilterReader;
 import org.apache.tools.ant.filters.ChainableReader;
 import org.apache.tools.ant.types.AntFilterReader;
 import org.apache.tools.ant.types.FilterChain;
-import org.apache.tools.ant.types.Parameter;
 import org.apache.tools.ant.types.Parameterizable;
 import org.apache.tools.ant.types.Path;
 import org.apache.tools.ant.util.FileUtils;
@@ -44,6 +47,37 @@ import org.apache.tools.ant.util.FileUtils;
  *
  */
 public final class ChainReaderHelper {
+    /**
+     * Created type.
+     */
+    public class ChainReader extends FilterReader {
+
+        private List<AntClassLoader> cleanupLoaders;
+
+        private ChainReader(Reader in, List<AntClassLoader> cleanupLoaders) {
+            super(in);
+            this.cleanupLoaders = cleanupLoaders;
+        }
+
+        public String readFully() throws IOException {
+            return ChainReaderHelper.this.readFully(this);
+        }
+        
+        @Override
+        public void close() throws IOException {
+            cleanUpClassLoaders(cleanupLoaders);
+            super.close();
+        }
+        
+        @Override
+        protected void finalize() throws Throwable {
+            try {
+                close();
+            } finally {
+                super.finalize();
+            }
+        }
+    }
 
     // default buffer size
     private static final int DEFAULT_BUFFER_SIZE = 8192;
@@ -61,7 +95,7 @@ public final class ChainReaderHelper {
     /**
      * Chain of filters
      */
-    public Vector<FilterChain> filterChains = new Vector<FilterChain>();
+    public Vector<FilterChain> filterChains = new Vector<>();
 
     /** The Ant project */
     private Project project = null;
@@ -69,7 +103,25 @@ public final class ChainReaderHelper {
     // CheckStyle:VisibilityModifier ON
 
     /**
-     * Sets the primary reader
+     * Default constructor.
+     */
+    public ChainReaderHelper() {
+    }
+
+    /**
+     * Convenience constructor.
+     * @param project
+     * @param primaryReader
+     * @param filterChains
+     */
+    public ChainReaderHelper(Project project, Reader primaryReader,
+        Iterable<FilterChain> filterChains) {
+        withProject(project).withPrimaryReader(primaryReader)
+            .withFilterChains(filterChains);
+    }
+
+    /**
+     * Sets the primary {@link Reader}
      * @param rdr the reader object
      */
     public void setPrimaryReader(Reader rdr) {
@@ -77,6 +129,16 @@ public final class ChainReaderHelper {
     }
 
     /**
+     * Fluent primary {@link Reader} mutator.
+     * @param rdr
+     * @return {@code this}
+     */
+    public ChainReaderHelper withPrimaryReader(Reader rdr) {
+        setPrimaryReader(rdr);
+        return this;
+    }
+
+    /**
      * Set the project to work with
      * @param project the current project
      */
@@ -85,6 +147,16 @@ public final class ChainReaderHelper {
     }
 
     /**
+     * Fluent {@link Project} mutator.
+     * @param project
+     * @return {@code this}
+     */
+    public ChainReaderHelper withProject(Project project) {
+        setProject(project);
+        return this;
+    }
+
+    /**
      * Get the project
      *
      * @return the current project
@@ -103,6 +175,16 @@ public final class ChainReaderHelper {
     }
 
     /**
+     * Fluent buffer size mutator.
+     * @param size
+     * @return {@code this}
+     */
+    public ChainReaderHelper withBufferSize(int size) {
+        setBufferSize(size);
+        return this;
+    }
+
+    /**
      * Sets the collection of filter reader sets
      *
      * @param fchain the filter chains collection
@@ -112,42 +194,56 @@ public final class ChainReaderHelper {
     }
 
     /**
+     * Fluent {@code filterChains} mutator.
+     * @param filterChains
+     * @return {@code this}
+     */
+    public ChainReaderHelper withFilterChains(Iterable<FilterChain> filterChains) {
+        final Vector<FilterChain> fcs;
+        if (filterChains instanceof Vector<?>) {
+            fcs = (Vector<FilterChain>) filterChains;
+        } else {
+            fcs = new Vector<>();
+            filterChains.forEach(fcs::add);
+        }
+        setFilterChains(fcs);
+        return this;
+    }
+
+    /**
+     * Fluent mechanism to apply some {@link Consumer}.
+     * @param consumer
+     * @return {@code this}
+     */
+    public ChainReaderHelper with(Consumer<ChainReaderHelper> consumer) {
+        consumer.accept(this);
+        return this;
+    }
+
+    /**
      * Assemble the reader
      * @return the assembled reader
      * @exception BuildException if an error occurs
      */
-    public Reader getAssembledReader() throws BuildException {
+    public ChainReader getAssembledReader() throws BuildException {
         if (primaryReader == null) {
             throw new BuildException("primaryReader must not be null.");
         }
 
         Reader instream = primaryReader;
-        final int filterReadersCount = filterChains.size();
-        final Vector<Object> finalFilters = new Vector<Object>();
-        final ArrayList<AntClassLoader> classLoadersToCleanUp =
-            new ArrayList<AntClassLoader>();
-
-        for (int i = 0; i < filterReadersCount; i++) {
-            final FilterChain filterchain =
-                filterChains.elementAt(i);
-            final Vector<Object> filterReaders = filterchain.getFilterReaders();
-            final int readerCount = filterReaders.size();
-            for (int j = 0; j < readerCount; j++) {
-                finalFilters.addElement(filterReaders.elementAt(j));
-            }
-        }
+        final List<AntClassLoader> classLoadersToCleanUp = new ArrayList<>();
 
-        final int filtersCount = finalFilters.size();
-
-        if (filtersCount > 0) {
+        final List<Object> finalFilters =
+            filterChains.stream().map(FilterChain::getFilterReaders)
+                .flatMap(Collection::stream).collect(Collectors.toList());
+        
+        if (!finalFilters.isEmpty()) {
             boolean success = false;
             try {
-                for (int i = 0; i < filtersCount; i++) {
-                    Object o = finalFilters.elementAt(i);
-
+                for (Object o : finalFilters) {
                     if (o instanceof AntFilterReader) {
                         instream =
-                            expandReader((AntFilterReader) finalFilters.elementAt(i),
+                            expandReader((AntFilterReader) o,
                                          instream, classLoadersToCleanUp);
                     } else if (o instanceof ChainableReader) {
                         setProjectOnObject(o);
@@ -157,26 +253,12 @@ public final class ChainReaderHelper {
                 }
                 success = true;
             } finally {
-                if (!success && classLoadersToCleanUp.size() > 0) {
+                if (!(success || classLoadersToCleanUp.isEmpty())) {
                     cleanUpClassLoaders(classLoadersToCleanUp);
                 }
             }
         }
-        final Reader finalReader = instream;
-        return classLoadersToCleanUp.size() == 0 ? finalReader
-            : new FilterReader(finalReader) {
-                    public void close() throws IOException {
-                        FileUtils.close(in);
-                        cleanUpClassLoaders(classLoadersToCleanUp);
-                    }
-                    protected void finalize() throws Throwable {
-                        try {
-                            close();
-                        } finally {
-                            super.finalize();
-                        }
-                    }
-                };
+        return new ChainReader(instream, classLoadersToCleanUp);
     }
 
     /**
@@ -199,9 +281,7 @@ public final class ChainReaderHelper {
      * Deregisters Classloaders from the project so GC can remove them later.
      */
     private static void cleanUpClassLoaders(List<AntClassLoader> loaders) {
-        for (Iterator<AntClassLoader> it = loaders.iterator(); it.hasNext();) {
-            it.next().cleanup();
-        }
+        loaders.forEach(AntClassLoader::cleanup);
     }
 
     /**
@@ -211,8 +291,7 @@ public final class ChainReaderHelper {
      * @return the contents of the file as a string
      * @exception IOException if an error occurs
      */
-    public String readFully(Reader rdr)
-        throws IOException {
+    public String readFully(Reader rdr) throws IOException {
         return FileUtils.readFully(rdr, bufferSize);
     }
 
@@ -227,57 +306,45 @@ public final class ChainReaderHelper {
                                 final List<AntClassLoader> classLoadersToCleanUp) {
         final String className = filter.getClassName();
         final Path classpath = filter.getClasspath();
-        final Project pro = filter.getProject();
         if (className != null) {
             try {
-                Class<?> clazz = null;
-                if (classpath == null) {
-                    clazz = Class.forName(className);
-                } else {
-                    AntClassLoader al = pro.createClassLoader(classpath);
-                    classLoadersToCleanUp.add(al);
-                    clazz = Class.forName(className, true, al);
-                }
-                if (clazz != null) {
-                    if (!FilterReader.class.isAssignableFrom(clazz)) {
-                        throw new BuildException(className + " does not extend"
-                                                 + " java.io.FilterReader");
-                    }
-                    final Constructor<?>[] constructors = clazz.getConstructors();
-                    int j = 0;
-                    boolean consPresent = false;
-                    for (; j < constructors.length; j++) {
-                        Class<?>[] types = constructors[j].getParameterTypes();
-                        if (types.length == 1
-                            && types[0].isAssignableFrom(Reader.class)) {
-                            consPresent = true;
-                            break;
-                        }
-                    }
-                    if (!consPresent) {
-                        throw new BuildException(className + " does not define"
-                                                 + " a public constructor"
-                                                 + " that takes in a Reader"
-                                                 + " as its single argument.");
-                    }
-                    final Reader[] rdr = {ancestor};
-                    Reader instream =
-                        (Reader) constructors[j].newInstance((Object[]) rdr);
-                    setProjectOnObject(instream);
-                    if (Parameterizable.class.isAssignableFrom(clazz)) {
-                        final Parameter[] params = filter.getParams();
-                        ((Parameterizable) instream).setParameters(params);
+                Class<? extends FilterReader> clazz;
+                try {
+                    if (classpath == null) {
+                        clazz = Class.forName(className)
+                            .asSubclass(FilterReader.class);
+                    } else {
+                        AntClassLoader al =
+                            filter.getProject().createClassLoader(classpath);
+                        classLoadersToCleanUp.add(al);
+                        clazz = Class.forName(className, true, al)
+                            .asSubclass(FilterReader.class);
                     }
-                    return instream;
+                } catch (ClassCastException ex) {
+                    throw new BuildException("%s does not extend %s", className,
+                        FilterReader.class.getName());
+                }
+                Optional<Constructor<?>> ctor =
+                    Stream.of(clazz.getConstructors())
+                        .filter(c -> c.getParameterCount() == 1
+                            && c.getParameterTypes()[0]
+                                .isAssignableFrom(Reader.class))
+                        .findFirst();
+
+                Object instream = ctor
+                    .orElseThrow(() -> new BuildException(
+                        "%s does not define a public constructor that takes in a %s as its single argument.",
+                        className, Reader.class.getSimpleName()))
+                    .newInstance(ancestor);
+
+                setProjectOnObject(instream);
+                if (Parameterizable.class.isAssignableFrom(clazz)) {
+                    ((Parameterizable) instream).setParameters(filter.getParams());
                 }
-            } catch (final ClassNotFoundException cnfe) {
-                throw new BuildException(cnfe);
-            } catch (final InstantiationException ie) {
-                throw new BuildException(ie);
-            } catch (final IllegalAccessException iae) {
-                throw new BuildException(iae);
-            } catch (final InvocationTargetException ite) {
-                throw new BuildException(ite);
+                return (Reader) instream;
+            } catch (ClassNotFoundException | InstantiationException
+                    | IllegalAccessException | InvocationTargetException ex) {
+                throw new BuildException(ex);
             }
         }
         // Ant 1.7.1 and earlier ignore <filterreader> without a

http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/helper/ProjectHelper2.java b/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
index 1fce8bc..313763a 100644
--- a/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
+++ b/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
@@ -88,6 +88,7 @@ public class ProjectHelper2 extends ProjectHelper {
      *
      * @since Ant 1.8.0
      */
+    @Override
     public boolean canParseAntlibDescriptor(Resource resource) {
         return true;
     }
@@ -102,6 +103,7 @@ public class ProjectHelper2 extends ProjectHelper {
      *
      * @since Ant 1.8.0
      */
+    @Override
     public UnknownElement parseAntlibDescriptor(Project containingProject,
                                                 Resource resource) {
         URLProvider up = resource.as(URLProvider.class);
@@ -143,6 +145,7 @@ public class ProjectHelper2 extends ProjectHelper {
      * @param source  the xml source
      * @exception BuildException if an error occurs
      */
+    @Override
     public void parse(Project project, Object source) throws BuildException {
         getImportStack().addElement(source);
         AntXMLContext context = null;
@@ -256,7 +259,7 @@ public class ProjectHelper2 extends ProjectHelper {
                     zf = new ZipFile(org.apache.tools.ant.launch.Locator
                                      .fromJarURI(uri), "UTF-8");
                     inputStream =
-                        zf.getInputStream(zf.getEntry(uri.substring(pling + 1)));
+                        zf.getInputStream(zf.getEntry(uri.substring(pling + 2)));
                 } else {
                     URLConnection conn = url.openConnection();
                     conn.setUseCaches(false);
@@ -521,6 +524,7 @@ public class ProjectHelper2 extends ProjectHelper {
          *                 document. Will not be <code>null</code>.
          * @return an inputsource for this identifier
          */
+        @Override
         public InputSource resolveEntity(String publicId, String systemId) {
 
             context.getProject().log("resolving systemId: " + systemId, Project.MSG_VERBOSE);
@@ -566,6 +570,7 @@ public class ProjectHelper2 extends ProjectHelper {
          * @exception org.xml.sax.SAXParseException if the tag given is not
          *                              <code>"project"</code>
          */
+        @Override
         public void startElement(String uri, String tag, String qname, Attributes attrs)
             throws SAXParseException {
             AntHandler next = currentHandler.onStartChild(uri, tag, qname, attrs, context);
@@ -580,6 +585,7 @@ public class ProjectHelper2 extends ProjectHelper {
          * @param locator The locator used by the parser.
          *                Will not be <code>null</code>.
          */
+        @Override
         public void setDocumentLocator(Locator locator) {
             context.setLocator(locator);
         }
@@ -595,9 +601,10 @@ public class ProjectHelper2 extends ProjectHelper {
          *
          * @exception SAXException in case of error (not thrown in this implementation)
          */
+        @Override
         public void endElement(String uri, String name, String qName) throws SAXException {
             currentHandler.onEndElement(uri, name, context);
-            AntHandler prev = (AntHandler) antHandlers.pop();
+            AntHandler prev = antHandlers.pop();
             currentHandler = prev;
             if (currentHandler != null) {
                 currentHandler.onEndChild(uri, name, qName, context);
@@ -612,6 +619,7 @@ public class ProjectHelper2 extends ProjectHelper {
          * @param count The number of characters to read.
          * @exception SAXParseException if an error occurs
          */
+        @Override
         public void characters(char[] buf, int start, int count) throws SAXParseException {
             currentHandler.characters(buf, start, count, context);
         }
@@ -622,6 +630,7 @@ public class ProjectHelper2 extends ProjectHelper {
          * @param prefix the namespace prefix
          * @param uri the namespace uri
          */
+        @Override
         public void startPrefixMapping(String prefix, String uri) {
             context.startPrefixMapping(prefix, uri);
         }
@@ -631,6 +640,7 @@ public class ProjectHelper2 extends ProjectHelper {
          *
          * @param prefix the prefix that is not mapped anymore
          */
+        @Override
         public void endPrefixMapping(String prefix) {
             context.endPrefixMapping(prefix);
         }
@@ -654,6 +664,7 @@ public class ProjectHelper2 extends ProjectHelper {
          * @return The project handler that handles subelements of project
          * @exception SAXParseException if the qualified name is not "project".
          */
+        @Override
         public AntHandler onStartChild(String uri, String name, String qname, Attributes attrs,
                                        AntXMLContext context) throws SAXParseException {
             if (name.equals("project")
@@ -693,6 +704,7 @@ public class ProjectHelper2 extends ProjectHelper {
          *            encountered or if the <code>"default"</code> attribute
          *            is missing.
          */
+        @Override
         public void onStartElement(String uri, String tag, String qname, Attributes attrs,
                                    AntXMLContext context) throws SAXParseException {
             String baseDir = null;
@@ -849,6 +861,7 @@ public class ProjectHelper2 extends ProjectHelper {
          *            <code>"extension-point"</code>
          *            or a data type definition
          */
+        @Override
         public AntHandler onStartChild(String uri, String name, String qname, Attributes attrs,
                                        AntXMLContext context) throws SAXParseException {
             return (name.equals("target") || name.equals("extension-point"))
@@ -882,6 +895,7 @@ public class ProjectHelper2 extends ProjectHelper {
          * @exception SAXParseException if an unexpected attribute is encountered
          *            or if the <code>"name"</code> attribute is missing.
          */
+        @Override
         public void onStartElement(String uri, String tag, String qname, Attributes attrs,
                                    AntXMLContext context) throws SAXParseException {
             String name = null;
@@ -1062,6 +1076,7 @@ public class ProjectHelper2 extends ProjectHelper {
          * @exception SAXParseException if an error occurs when initialising
          *                              the appropriate child handler
          */
+        @Override
         public AntHandler onStartChild(String uri, String name, String qname, Attributes attrs,
                                        AntXMLContext context) throws SAXParseException {
             return ProjectHelper2.elementHandler;
@@ -1075,6 +1090,7 @@ public class ProjectHelper2 extends ProjectHelper {
          * @param tag The name of the element.
          * @param context The current context.
          */
+        @Override
         public void onEndElement(String uri, String tag, AntXMLContext context) {
             context.setCurrentTarget(context.getImplicitTarget());
         }
@@ -1109,6 +1125,7 @@ public class ProjectHelper2 extends ProjectHelper {
          * @exception SAXParseException in case of error (not thrown in
          *                              this implementation)
          */
+        @Override
         public void onStartElement(String uri, String tag, String qname, Attributes attrs,
                                    AntXMLContext context) throws SAXParseException {
             RuntimeConfigurable parentWrapper = context.currentWrapper();
@@ -1195,6 +1212,7 @@ public class ProjectHelper2 extends ProjectHelper {
          *
          * @see ProjectHelper#addText(Project,java.lang.Object,char[],int,int)
          */
+        @Override
         public void characters(char[] buf, int start, int count,
                                AntXMLContext context) throws SAXParseException {
             RuntimeConfigurable wrapper = context.currentWrapper();
@@ -1218,6 +1236,7 @@ public class ProjectHelper2 extends ProjectHelper {
          * @exception SAXParseException if an error occurs when initialising
          *                              the appropriate child handler
          */
+        @Override
         public AntHandler onStartChild(String uri, String tag, String qname, Attributes attrs,
                                        AntXMLContext context) throws SAXParseException {
             return ProjectHelper2.elementHandler;
@@ -1231,6 +1250,7 @@ public class ProjectHelper2 extends ProjectHelper {
          * @param tag The name of the element.
          * @param context The current context.
          */
+        @Override
         public void onEndElement(String uri, String tag, AntXMLContext context) {
             context.popWrapper();
         }

http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/input/MultipleChoiceInputRequest.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/input/MultipleChoiceInputRequest.java b/src/main/org/apache/tools/ant/input/MultipleChoiceInputRequest.java
index 4baab8f..8f3b086 100644
--- a/src/main/org/apache/tools/ant/input/MultipleChoiceInputRequest.java
+++ b/src/main/org/apache/tools/ant/input/MultipleChoiceInputRequest.java
@@ -18,6 +18,7 @@
 
 package org.apache.tools.ant.input;
 
+import java.util.Collection;
 import java.util.LinkedHashSet;
 import java.util.Vector;
 
@@ -33,26 +34,39 @@ public class MultipleChoiceInputRequest extends InputRequest {
      * @param prompt The prompt to show to the user.  Must not be null.
      * @param choices holds all input values that are allowed.
      *                Must not be null.
+     * @deprecated Use {@link #MultipleChoiceInputRequest(String,Collection)} instead
      */
+    @Deprecated
     public MultipleChoiceInputRequest(String prompt, Vector<String> choices) {
+        this(prompt, (Collection<String>) choices);
+    }
+
+    /**
+     * @param prompt The prompt to show to the user.  Must not be null.
+     * @param choices holds all input values that are allowed.
+     *                Must not be null.
+     */
+    public MultipleChoiceInputRequest(String prompt, Collection<String> choices) {
         super(prompt);
         if (choices == null) {
             throw new IllegalArgumentException("choices must not be null");
         }
-        this.choices = new LinkedHashSet<String>(choices);
+        this.choices = new LinkedHashSet<>(choices);
     }
 
     /**
      * @return The possible values.
      */
     public Vector<String> getChoices() {
-        return new Vector<String>(choices);
+        return new Vector<>(choices);
     }
 
     /**
      * @return true if the input is one of the allowed values.
      */
+    @Override
     public boolean isInputValid() {
-        return choices.contains(getInput()) || ("".equals(getInput()) && getDefaultValue() != null);
+        return choices.contains(getInput())
+            || ("".equals(getInput()) && getDefaultValue() != null);
     }
 }

http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/launch/Launcher.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/launch/Launcher.java b/src/main/org/apache/tools/ant/launch/Launcher.java
index 534bbfb..e41628b 100644
--- a/src/main/org/apache/tools/ant/launch/Launcher.java
+++ b/src/main/org/apache/tools/ant/launch/Launcher.java
@@ -25,9 +25,6 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.StringTokenizer;
 
-
-
-
 /**
  * This is a launcher for Ant.
  *
@@ -35,9 +32,6 @@ import java.util.StringTokenizer;
  */
 public class Launcher {
 
-    private Launcher() {
-    }
-
     /**
      * The Ant Home (installation) Directory property.
      * {@value}
@@ -63,11 +57,6 @@ public class Launcher {
     public static final String ANT_PRIVATELIB = "lib";
 
     /**
-     * launch diagnostics flag; for debugging trouble at launch time.
-     */
-    public boolean launchDiag = false;
-
-    /**
      * The location of a per-user library directory.
      * <p>
      * It's value is the concatenation of {@link #ANT_PRIVATEDIR}
@@ -127,6 +116,13 @@ public class Launcher {
         }
     }
 
+    /**
+     * launch diagnostics flag; for debugging trouble at launch time.
+     */
+    public boolean launchDiag = false;
+
+    private Launcher() {
+    }
 
     /**
      * Add a CLASSPATH or -lib to lib path urls.
@@ -156,7 +152,7 @@ public class Launcher {
                 }
             }
 
-            final URL url = Locator.fileToURL(element);
+            final URL url = new URL(element.toURI().toASCIIString());
             if (launchDiag) {
                 System.out.println("adding library URL: " + url);
             }
@@ -193,44 +189,45 @@ public class Launcher {
         }
 
         if (!antHome.exists()) {
-            throw new LaunchException("Ant home is set incorrectly or "
-                + "ant could not be located (estimated value="+antHome.getAbsolutePath()+")");
+            throw new LaunchException(
+                "Ant home is set incorrectly or ant could not be located (estimated value="
+                    + antHome.getAbsolutePath() + ")");
         }
 
-        final List<String> libPaths = new ArrayList<String>();
+        final List<String> libPaths = new ArrayList<>();
         String cpString = null;
-        final List<String> argList = new ArrayList<String>();
+        final List<String> argList = new ArrayList<>();
         String[] newArgs;
         boolean  noUserLib = false;
         boolean  noClassPath = false;
 
         for (int i = 0; i < args.length; ++i) {
-            if (args[i].equals("-lib")) {
+            if ("-lib".equals(args[i])) {
                 if (i == args.length - 1) {
-                    throw new LaunchException("The -lib argument must "
-                        + "be followed by a library location");
+                    throw new LaunchException(
+                        "The -lib argument must be followed by a library location");
                 }
                 libPaths.add(args[++i]);
-            } else if (args[i].equals("-cp")) {
+            } else if ("-cp".equals(args[i])) {
                 if (i == args.length - 1) {
-                    throw new LaunchException("The -cp argument must "
-                        + "be followed by a classpath expression");
+                    throw new LaunchException(
+                        "The -cp argument must be followed by a classpath expression");
                 }
                 if (cpString != null) {
-                    throw new LaunchException("The -cp argument must "
-                        + "not be repeated");
+                    throw new LaunchException(
+                        "The -cp argument must not be repeated");
                 }
                 cpString = args[++i];
-            } else if (args[i].equals("--nouserlib") || args[i].equals("-nouserlib")) {
+            } else if ("--nouserlib".equals(args[i]) || "-nouserlib".equals(args[i])) {
                 noUserLib = true;
-            } else if (args[i].equals("--launchdiag")) {
+            } else if ("--launchdiag".equals(args[i])) {
                 launchDiag = true;
-            } else if (args[i].equals("--noclasspath") || args[i].equals("-noclasspath")) {
+            } else if ("--noclasspath".equals(args[i]) || "-noclasspath".equals(args[i])) {
                 noClassPath = true;
-            } else if (args[i].equals("-main")) {
+            } else if ("-main".equals(args[i])) {
                 if (i == args.length - 1) {
-                    throw new LaunchException("The -main argument must "
-                            + "be followed by a library location");
+                    throw new LaunchException(
+                        "The -main argument must be followed by a library location");
                 }
                 mainClassname = args[++i];
             } else {
@@ -262,8 +259,8 @@ public class Launcher {
             libURLs, userURLs, systemURLs, toolsJAR);
 
         // now update the class.path property
-        final StringBuffer baseClassPath
-            = new StringBuffer(System.getProperty(JAVA_CLASS_PATH));
+        final StringBuilder baseClassPath
+            = new StringBuilder(System.getProperty(JAVA_CLASS_PATH));
         if (baseClassPath.charAt(baseClassPath.length() - 1)
                 == File.pathSeparatorChar) {
             baseClassPath.setLength(baseClassPath.length() - 1);
@@ -278,12 +275,12 @@ public class Launcher {
 
         final URLClassLoader loader = new URLClassLoader(jars, Launcher.class.getClassLoader());
         Thread.currentThread().setContextClassLoader(loader);
-        Class<?> mainClass = null;
+        Class<? extends AntMain> mainClass = null;
         int exitCode = 0;
         Throwable thrown=null;
         try {
-            mainClass = loader.loadClass(mainClassname);
-            final AntMain main = (AntMain) mainClass.newInstance();
+            mainClass = loader.loadClass(mainClassname).asSubclass(AntMain.class);
+            final AntMain main = mainClass.newInstance();
             main.startAnt(newArgs, null, null);
         } catch (final InstantiationException ex) {
             System.err.println(
@@ -320,7 +317,7 @@ public class Launcher {
      */
     private URL[] getLibPathURLs(final String cpString, final List<String> libPaths)
         throws MalformedURLException {
-        final List<URL> libPathURLs = new ArrayList<URL>();
+        final List<URL> libPathURLs = new ArrayList<>();
 
         if (cpString != null) {
             addPath(cpString, false, libPathURLs);
@@ -389,7 +386,7 @@ public class Launcher {
             systemJars.length);
 
         if (toolsJar != null) {
-            jars[jars.length - 1] = Locator.fileToURL(toolsJar);
+            jars[jars.length - 1] = new URL(toolsJar.toURI().toASCIIString());
         }
         return jars;
     }
@@ -407,8 +404,8 @@ public class Launcher {
     }
 
     private void logPath(final String name,final File path) {
-        if(launchDiag) {
-            System.out.println(name+"= \""+path+"\"");
+        if (launchDiag) {
+            System.out.println(name + "= \"" + path + "\"");
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/launch/Locator.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/launch/Locator.java b/src/main/org/apache/tools/ant/launch/Locator.java
index 2e8c37d..436d5f0 100644
--- a/src/main/org/apache/tools/ant/launch/Locator.java
+++ b/src/main/org/apache/tools/ant/launch/Locator.java
@@ -19,7 +19,6 @@ package org.apache.tools.ant.launch;
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.FilenameFilter;
 import java.io.UnsupportedEncodingException;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -27,6 +26,7 @@ import java.nio.charset.StandardCharsets;
 import java.text.CharacterIterator;
 import java.text.StringCharacterIterator;
 import java.util.Locale;
+import java.util.stream.Stream;
 
 // CheckStyle:LineLengthCheck OFF - urls are long!
 /**
@@ -95,11 +95,6 @@ public final class Locator {
             gAfterEscaping2[ch] = gHexChs[ch & NIBBLE_MASK];
         }
     }
-    /**
-     * Not instantiable
-     */
-    private Locator() {
-    }
 
     /**
      * Find the directory or jar file the class has been loaded from.
@@ -130,7 +125,7 @@ public final class Locator {
         if (c == null) {
             c = Locator.class.getClassLoader();
         }
-        URL url = null;
+        URL url;
         if (c == null) {
             url = ClassLoader.getSystemResource(resource);
         } else {
@@ -141,21 +136,19 @@ public final class Locator {
             try {
                 if (u.startsWith("jar:file:")) {
                     return new File(fromJarURI(u));
-                } else if (u.startsWith("file:")) {
+                }
+                if (u.startsWith("file:")) {
                     int tail = u.indexOf(resource);
                     String dirName = u.substring(0, tail);
                     return new File(fromURI(dirName));
                 }
             } catch (IllegalArgumentException e) {
                 //unable to determine the URI for reasons unknown.
-                return null;
             }
         }
         return null;
     }
 
-
-
     /**
      * Constructs a file path from a <code>file:</code> URI.
      *
@@ -234,7 +227,7 @@ public final class Locator {
         if (url == null || !("file".equals(url.getProtocol()))) {
             throw new IllegalArgumentException(ERROR_NOT_FILE_URI + uri);
         }
-        StringBuffer buf = new StringBuffer(url.getHost());
+        StringBuilder buf = new StringBuilder(url.getHost());
         if (buf.length() > 0) {
             buf.insert(0, File.separatorChar).insert(0, File.separatorChar);
         }
@@ -330,7 +323,7 @@ public final class Locator {
         int i = 0;
         int len = path.length();
         int ch = 0;
-        StringBuffer sb = null;
+        StringBuilder sb = null;
         for (; i < len; i++) {
             ch = path.charAt(i);
             // if it's not an ASCII character, break here, and use UTF-8 encoding
@@ -339,7 +332,7 @@ public final class Locator {
             }
             if (gNeedEscaping[ch]) {
                 if (sb == null) {
-                    sb = new StringBuffer(path.substring(0, i));
+                    sb = new StringBuilder(path.substring(0, i));
                 }
                 sb.append('%');
                 sb.append(gAfterEscaping1[ch]);
@@ -353,17 +346,15 @@ public final class Locator {
         // we saw some non-ascii character
         if (i < len) {
             if (sb == null) {
-                sb = new StringBuffer(path.substring(0, i));
+                sb = new StringBuilder(path.substring(0, i));
             }
             // get UTF-8 bytes for the remaining sub-string
-            byte[] bytes = null;
-            byte b;
-            bytes = path.substring(i).getBytes(StandardCharsets.UTF_8);
+            byte[] bytes = path.substring(i).getBytes(StandardCharsets.UTF_8);
             len = bytes.length;
 
             // for each byte
             for (i = 0; i < len; i++) {
-                b = bytes[i];
+                byte b = bytes[i];
                 // for non-ascii character: make it positive, then escape
                 if (b < 0) {
                     ch = b + BYTE_SIZE;
@@ -466,7 +457,7 @@ public final class Locator {
      */
     public static URL[] getLocationURLs(File location)
          throws MalformedURLException {
-        return getLocationURLs(location, new String[]{".jar"});
+        return getLocationURLs(location, ".jar");
     }
 
     /**
@@ -484,7 +475,7 @@ public final class Locator {
      *            formed.
      */
     public static URL[] getLocationURLs(File location,
-                                        final String[] extensions)
+                                        final String... extensions)
          throws MalformedURLException {
         URL[] urls = new URL[0];
 
@@ -503,22 +494,21 @@ public final class Locator {
             }
             return urls;
         }
-        File[] matches = location.listFiles(
-            new FilenameFilter() {
-                public boolean accept(File dir, String name) {
-                    String littleName = name.toLowerCase(Locale.ENGLISH);
-                    for (int i = 0; i < extensions.length; ++i) {
-                        if (littleName.endsWith(extensions[i])) {
-                            return true;
-                        }
-                    }
-                    return false;
-                }
-            });
+        File[] matches = location.listFiles((dir, name) -> {
+            String littleName = name.toLowerCase(Locale.ENGLISH);
+            return Stream.of(extensions).anyMatch(x -> littleName.endsWith(x));
+        });
         urls = new URL[matches.length];
         for (int i = 0; i < matches.length; ++i) {
             urls[i] = fileToURL(matches[i]);
         }
         return urls;
     }
+
+    /**
+     * Not instantiable
+     */
+    private Locator() {
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/listener/AnsiColorLogger.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/listener/AnsiColorLogger.java b/src/main/org/apache/tools/ant/listener/AnsiColorLogger.java
index 0e29b40..9370f87 100644
--- a/src/main/org/apache/tools/ant/listener/AnsiColorLogger.java
+++ b/src/main/org/apache/tools/ant/listener/AnsiColorLogger.java
@@ -213,7 +213,7 @@ public class AnsiColorLogger extends DefaultLogger {
                 colorsSet = true;
             }
 
-            final StringBuffer msg = new StringBuffer(message);
+            final StringBuilder msg = new StringBuilder(message);
             switch (priority) {
                 case Project.MSG_ERR:
                     msg.insert(0, errColor);

http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/listener/CommonsLoggingListener.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/listener/CommonsLoggingListener.java b/src/main/org/apache/tools/ant/listener/CommonsLoggingListener.java
index 32474ee..2890b82 100644
--- a/src/main/org/apache/tools/ant/listener/CommonsLoggingListener.java
+++ b/src/main/org/apache/tools/ant/listener/CommonsLoggingListener.java
@@ -102,6 +102,7 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger {
     }
 
     /** {@inheritDoc}. */
+    @Override
     public void buildStarted(final BuildEvent event) {
         final String categoryString = PROJECT_LOG;
         final Log log = getLog(categoryString, null);
@@ -112,6 +113,7 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger {
     }
 
     /** {@inheritDoc}. */
+    @Override
     public void buildFinished(final BuildEvent event) {
         if (initialized) {
             final String categoryString = PROJECT_LOG;
@@ -130,6 +132,7 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger {
      * @see BuildListener#targetStarted
      */
     /** {@inheritDoc}. */
+    @Override
     public void targetStarted(final BuildEvent event) {
         if (initialized) {
             final Log log = getLog(TARGET_LOG,
@@ -145,6 +148,7 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger {
      * @see BuildListener#targetFinished
      */
     /** {@inheritDoc}. */
+    @Override
     public void targetFinished(final BuildEvent event) {
         if (initialized) {
             final String targetName = event.getTarget().getName();
@@ -164,6 +168,7 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger {
      * @see BuildListener#taskStarted
      */
     /** {@inheritDoc}. */
+    @Override
     public void taskStarted(final BuildEvent event) {
         if (initialized) {
             final Task task = event.getTask();
@@ -186,6 +191,7 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger {
      * @see BuildListener#taskFinished
      */
     /** {@inheritDoc}. */
+    @Override
     public void taskFinished(final BuildEvent event) {
         if (initialized) {
             final Task task = event.getTask();
@@ -215,16 +221,16 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger {
      * @see BuildListener#messageLogged
      */
     /** {@inheritDoc}. */
+    @Override
     public void messageLogged(final BuildEvent event) {
         if (initialized) {
             Object categoryObject = event.getTask();
-            String categoryString = null;
+            String categoryString;
             String categoryDetail = null;
 
             if (categoryObject == null) {
                 categoryObject = event.getTarget();
                 if (categoryObject == null) {
-                    categoryObject = event.getProject();
                     categoryString = PROJECT_LOG;
                     categoryDetail = event.getProject().getName();
                 } else {
@@ -300,6 +306,7 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger {
      * This is not used, the logger config is used instead.
      * @param level ignored
      */
+    @Override
     public void setMessageOutputLevel(final int level) {
         // Use the logger config
     }
@@ -308,6 +315,7 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger {
      * Set the output print stream.
      * @param output the output stream
      */
+    @Override
     public void setOutputPrintStream(final PrintStream output) {
         this.out = output;
     }
@@ -317,6 +325,7 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger {
      * This is ignored.
      * @param emacsMode ignored
      */
+    @Override
     public void setEmacsMode(final boolean emacsMode) {
         // Doesn't make sense for c-l. Use the logger config
     }
@@ -325,6 +334,7 @@ public class CommonsLoggingListener implements BuildListener, BuildLogger {
      * Set the error print stream.
      * @param err the error stream
      */
+    @Override
     public void setErrorPrintStream(final PrintStream err) {
         this.err = err;
     }

http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/listener/Log4jListener.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/listener/Log4jListener.java b/src/main/org/apache/tools/ant/listener/Log4jListener.java
index 829f118..8210228 100644
--- a/src/main/org/apache/tools/ant/listener/Log4jListener.java
+++ b/src/main/org/apache/tools/ant/listener/Log4jListener.java
@@ -33,14 +33,14 @@ import org.apache.tools.ant.Task;
  */
 public class Log4jListener implements BuildListener {
 
-    /** Indicates if the listener was initialized. */
-    private final boolean initialized;
-
     /**
      * log category we log into
      */
     public static final String LOG_ANT = "org.apache.tools.ant";
 
+    /** Indicates if the listener was initialized. */
+    private final boolean initialized;
+
     /**
      * Construct the listener and make sure there is a valid appender.
      */
@@ -57,6 +57,7 @@ public class Log4jListener implements BuildListener {
      * @see BuildListener#buildStarted
      */
     /** {@inheritDoc}. */
+    @Override
     public void buildStarted(final BuildEvent event) {
         if (initialized) {
             final Logger log = Logger.getLogger(Project.class.getName());
@@ -68,6 +69,7 @@ public class Log4jListener implements BuildListener {
      * @see BuildListener#buildFinished
      */
     /** {@inheritDoc}. */
+    @Override
     public void buildFinished(final BuildEvent event) {
         if (initialized) {
             final Logger log = Logger.getLogger(Project.class.getName());
@@ -83,6 +85,7 @@ public class Log4jListener implements BuildListener {
      * @see BuildListener#targetStarted
      */
     /** {@inheritDoc}. */
+    @Override
     public void targetStarted(final BuildEvent event) {
         if (initialized) {
             final Logger log = Logger.getLogger(Target.class.getName());
@@ -94,6 +97,7 @@ public class Log4jListener implements BuildListener {
      * @see BuildListener#targetFinished
      */
     /** {@inheritDoc}. */
+    @Override
     public void targetFinished(final BuildEvent event) {
         if (initialized) {
             final String targetName = event.getTarget().getName();
@@ -111,6 +115,7 @@ public class Log4jListener implements BuildListener {
      * @see BuildListener#taskStarted
      */
     /** {@inheritDoc}. */
+    @Override
     public void taskStarted(final BuildEvent event) {
         if (initialized) {
             final Task task = event.getTask();
@@ -123,6 +128,7 @@ public class Log4jListener implements BuildListener {
      * @see BuildListener#taskFinished
      */
     /** {@inheritDoc}. */
+    @Override
     public void taskFinished(final BuildEvent event) {
         if (initialized) {
             final Task task = event.getTask();
@@ -140,6 +146,7 @@ public class Log4jListener implements BuildListener {
      * @see BuildListener#messageLogged
      */
     /** {@inheritDoc}. */
+    @Override
     public void messageLogged(final BuildEvent event) {
         if (initialized) {
             Object categoryObject = event.getTask();

http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/listener/MailLogger.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/listener/MailLogger.java b/src/main/org/apache/tools/ant/listener/MailLogger.java
index 25f5bab..cff2073 100644
--- a/src/main/org/apache/tools/ant/listener/MailLogger.java
+++ b/src/main/org/apache/tools/ant/listener/MailLogger.java
@@ -24,10 +24,12 @@ import java.io.PrintStream;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.Enumeration;
-import java.util.Hashtable;
+import java.util.Map;
 import java.util.Properties;
 import java.util.StringTokenizer;
 import java.util.Vector;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import org.apache.tools.ant.BuildEvent;
 import org.apache.tools.ant.BuildException;
@@ -97,21 +99,22 @@ import org.apache.tools.mail.MailMessage;
  *
  */
 public class MailLogger extends DefaultLogger {
+    private static final String DEFAULT_MIME_TYPE = "text/plain";
+
     /** Buffer in which the message is constructed prior to sending */
     private StringBuffer buffer = new StringBuffer();
 
-    private static final String DEFAULT_MIME_TYPE = "text/plain";
-
     /**
      *  Sends an e-mail with the log results.
      *
      * @param event the build finished event
      */
+    @Override
     public void buildFinished(BuildEvent event) {
         super.buildFinished(event);
 
         Project project = event.getProject();
-        Hashtable<String, Object> properties = project.getProperties();
+        Map<String, Object> properties = project.getProperties();
 
         // overlay specified properties file (if any), which overrides project
         // settings
@@ -168,8 +171,8 @@ public class MailLogger extends DefaultLogger {
                 .subject(getValue(
                              properties, prefix + ".subject",
                              (success) ? "Build Success" : "Build Failure"));
-            if (values.user().equals("")
-                && values.password().equals("")
+            if (values.user().isEmpty()
+                && values.password().isEmpty()
                 && !values.ssl() && !values.starttls()) {
                 sendMail(values, buffer.substring(0));
             } else {
@@ -310,6 +313,7 @@ public class MailLogger extends DefaultLogger {
      *
      * @param message the message being logger
      */
+    @Override
     protected void log(String message) {
         buffer.append(message).append(StringUtils.LINE_SEP);
     }
@@ -327,7 +331,7 @@ public class MailLogger extends DefaultLogger {
      * @exception  Exception  thrown if no default value is specified and the
      *      property is not present in properties.
      */
-    private String getValue(Hashtable<String, Object> properties, String name,
+    private String getValue(Map<String, Object> properties, String name,
                             String defaultValue) {
         String propertyName = "MailLogger." + name;
         String value = (String) properties.get(propertyName);
@@ -356,7 +360,7 @@ public class MailLogger extends DefaultLogger {
         mailMessage.setHeader("Date", DateUtils.getDateForHeader());
 
         mailMessage.from(values.from());
-        if (!values.replytoList().equals("")) {
+        if (!values.replytoList().isEmpty()) {
             StringTokenizer t = new StringTokenizer(
                 values.replytoList(), ", ", false);
             while (t.hasMoreTokens()) {
@@ -391,7 +395,7 @@ public class MailLogger extends DefaultLogger {
     private void sendMimeMail(Project project, Values values, String message) {
         Mailer mailer = null;
         try {
-            mailer = (Mailer) ClasspathUtils.newInstance(
+            mailer = ClasspathUtils.newInstance(
                     "org.apache.tools.ant.taskdefs.email.MimeMailer",
                     MailLogger.class.getClassLoader(), Mailer.class);
         } catch (BuildException e) {
@@ -400,7 +404,7 @@ public class MailLogger extends DefaultLogger {
             return;
         }
         // convert the replyTo string into a vector of emailaddresses
-        Vector<EmailAddress> replyToList = vectorizeEmailAddresses(values.replytoList());
+        Vector<EmailAddress> replyToList = splitEmailAddresses(values.replytoList());
         mailer.setHost(values.mailhost());
         mailer.setPort(values.port());
         mailer.setUser(values.user());
@@ -417,25 +421,20 @@ public class MailLogger extends DefaultLogger {
         mailer.setMessage(mymessage);
         mailer.setFrom(new EmailAddress(values.from()));
         mailer.setReplyToList(replyToList);
-        Vector<EmailAddress> toList = vectorizeEmailAddresses(values.toList());
+        Vector<EmailAddress> toList = splitEmailAddresses(values.toList());
         mailer.setToList(toList);
-        Vector<EmailAddress> toCcList = vectorizeEmailAddresses(values.toCcList());
+        Vector<EmailAddress> toCcList = splitEmailAddresses(values.toCcList());
         mailer.setCcList(toCcList);
-        Vector<EmailAddress> toBccList = vectorizeEmailAddresses(values.toBccList());
+        Vector<EmailAddress> toBccList = splitEmailAddresses(values.toBccList());
         mailer.setBccList(toBccList);
         mailer.setFiles(new Vector<File>());
         mailer.setSubject(values.subject());
         mailer.setHeaders(new Vector<Header>());
         mailer.send();
     }
-    private Vector<EmailAddress> vectorizeEmailAddresses(String listString) {
-        Vector<EmailAddress> emailList = new Vector<EmailAddress>();
-        StringTokenizer tokens = new StringTokenizer(listString, ",");
-        while (tokens.hasMoreTokens()) {
-            emailList.addElement(new EmailAddress(tokens.nextToken()));
-        }
-        return emailList;
+
+    private Vector<EmailAddress> splitEmailAddresses(String listString) {
+        return Stream.of(listString.split(",")).map(EmailAddress::new)
+            .collect(Collectors.toCollection(Vector::new));
     }
 }
-
-

http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/listener/ProfileLogger.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/listener/ProfileLogger.java b/src/main/org/apache/tools/ant/listener/ProfileLogger.java
index bbf5bb4..5dfe8ef 100644
--- a/src/main/org/apache/tools/ant/listener/ProfileLogger.java
+++ b/src/main/org/apache/tools/ant/listener/ProfileLogger.java
@@ -32,7 +32,7 @@ import org.apache.tools.ant.util.StringUtils;
  */
 public class ProfileLogger extends DefaultLogger {
 
-    private Map<Object, Date> profileData = new ConcurrentHashMap<Object, Date>();
+    private Map<Object, Date> profileData = new ConcurrentHashMap<>();
 
     /**
      * Logs a message to say that the target has started.
@@ -41,6 +41,7 @@ public class ProfileLogger extends DefaultLogger {
      *            An event with any relevant extra information. Must not be
      *            <code>null</code>.
      */
+    @Override
     public void targetStarted(BuildEvent event) {
         Date now = new Date();
         String name = "Target " + event.getTarget().getName();
@@ -55,8 +56,9 @@ public class ProfileLogger extends DefaultLogger {
      *            An event with any relevant extra information. Must not be
      *            <code>null</code>.
      */
+    @Override
     public void targetFinished(BuildEvent event) {
-        Date start = (Date) profileData.remove(event.getTarget());
+        Date start = profileData.remove(event.getTarget());
         String name = "Target " + event.getTarget().getName();
         logFinish(event, start, name);
     }
@@ -68,6 +70,7 @@ public class ProfileLogger extends DefaultLogger {
      *            An event with any relevant extra information. Must not be
      *            <code>null</code>.
      */
+    @Override
     public void taskStarted(BuildEvent event) {
         String name = event.getTask().getTaskName();
         Date now = new Date();
@@ -82,15 +85,16 @@ public class ProfileLogger extends DefaultLogger {
      *            An event with any relevant extra information. Must not be
      *            <code>null</code>.
      */
+    @Override
     public void taskFinished(BuildEvent event) {
-        Date start = (Date) profileData.remove(event.getTask());
+        Date start = profileData.remove(event.getTask());
         String name = event.getTask().getTaskName();
         logFinish(event, start, name);
     }
 
     private void logFinish(BuildEvent event, Date start, String name) {
         Date now = new Date();
-        String msg = null;
+        String msg;
         if (start != null) {
             long diff = now.getTime() - start.getTime();
             msg = StringUtils.LINE_SEP + name + ": finished " + now + " ("

http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/listener/SimpleBigProjectLogger.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/listener/SimpleBigProjectLogger.java b/src/main/org/apache/tools/ant/listener/SimpleBigProjectLogger.java
index 18f8dc6..7893287 100644
--- a/src/main/org/apache/tools/ant/listener/SimpleBigProjectLogger.java
+++ b/src/main/org/apache/tools/ant/listener/SimpleBigProjectLogger.java
@@ -33,14 +33,14 @@ public class SimpleBigProjectLogger extends NoBannerLogger {
      * @param event the event to work on
      * @return the target name -including the owning project name (if non-null)
      */
+    @Override
     protected String extractTargetName(BuildEvent event) {
         String targetName = super.extractTargetName(event);
         String projectName = extractProjectName(event);
-        if (projectName != null && targetName != null) {
-            return projectName + '.' + targetName;
-        } else {
+        if (projectName == null || targetName == null) {
             return targetName;
         }
+        return projectName + '.' + targetName;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/listener/TimestampedLogger.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/listener/TimestampedLogger.java b/src/main/org/apache/tools/ant/listener/TimestampedLogger.java
index 91296e3..70535e9 100644
--- a/src/main/org/apache/tools/ant/listener/TimestampedLogger.java
+++ b/src/main/org/apache/tools/ant/listener/TimestampedLogger.java
@@ -30,13 +30,13 @@ public class TimestampedLogger extends DefaultLogger {
      */
     public static final String SPACER = " - at ";
 
-
     /**
      * This is an override point: the message that indicates whether a build failed.
      * Subclasses can change/enhance the message.
      *
      * @return The classic "BUILD FAILED" plus a timestamp
      */
+    @Override
     protected String getBuildFailedMessage() {
         return super.getBuildFailedMessage() + SPACER + getTimestamp();
     }
@@ -47,6 +47,7 @@ public class TimestampedLogger extends DefaultLogger {
      *
      * @return The classic "BUILD SUCCESSFUL" plus a timestamp
      */
+    @Override
     protected String getBuildSuccessfulMessage() {
         return super.getBuildSuccessfulMessage() + SPACER + getTimestamp();
     }

http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/property/LocalProperties.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/property/LocalProperties.java b/src/main/org/apache/tools/ant/property/LocalProperties.java
index c9ce3af..d5bb9b7 100644
--- a/src/main/org/apache/tools/ant/property/LocalProperties.java
+++ b/src/main/org/apache/tools/ant/property/LocalProperties.java
@@ -36,8 +36,8 @@ public class LocalProperties
      * @return the localproperties.
      */
     public static synchronized LocalProperties get(Project project) {
-        LocalProperties l = (LocalProperties) project.getReference(
-            MagicNames.REFID_LOCAL_PROPERTIES);
+        LocalProperties l =
+            project.getReference(MagicNames.REFID_LOCAL_PROPERTIES);
         if (l == null) {
             l = new LocalProperties();
             project.addReference(MagicNames.REFID_LOCAL_PROPERTIES, l);
@@ -62,14 +62,11 @@ public class LocalProperties
      * Get the initial value.
      * @return a new localproperties stack.
      */
+    @Override
     protected synchronized LocalPropertyStack initialValue() {
         return new LocalPropertyStack();
     }
 
-    private LocalPropertyStack current() {
-        return (LocalPropertyStack) get();
-    }
-
     // --------------------------------------------------
     //
     //  Local property adding and scoping
@@ -81,17 +78,17 @@ public class LocalProperties
      * @param property the property name to add.
      */
     public void addLocal(String property) {
-        current().addLocal(property);
+        get().addLocal(property);
     }
 
     /** enter the scope */
     public void enterScope() {
-        current().enterScope();
+        get().enterScope();
     }
 
     /** exit the scope */
     public void exitScope() {
-        current().exitScope();
+        get().exitScope();
     }
 
     // --------------------------------------------------
@@ -105,7 +102,7 @@ public class LocalProperties
      * To be called from the parallel thread itself.
      */
     public void copy() {
-        set(current().copy());
+        set(get().copy());
     }
 
     // --------------------------------------------------
@@ -120,8 +117,9 @@ public class LocalProperties
      * @param helper the invoking PropertyHelper.
      * @return Object value.
      */
+    @Override
     public Object evaluate(String property, PropertyHelper helper) {
-        return current().evaluate(property, helper);
+        return get().evaluate(property, helper);
     }
 
     /**
@@ -131,9 +129,10 @@ public class LocalProperties
      * @param propertyHelper the invoking PropertyHelper.
      * @return true if this entity 'owns' the property.
      */
+    @Override
     public boolean setNew(
         String property, Object value, PropertyHelper propertyHelper) {
-        return current().setNew(property, value, propertyHelper);
+        return get().setNew(property, value, propertyHelper);
     }
 
     /**
@@ -143,10 +142,9 @@ public class LocalProperties
      * @param propertyHelper the invoking PropertyHelper.
      * @return true if this entity 'owns' the property.
      */
+    @Override
     public boolean set(
         String property, Object value, PropertyHelper propertyHelper) {
-        return current().set(property, value, propertyHelper);
+        return get().set(property, value, propertyHelper);
     }
 }
-
-

http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/property/LocalPropertyStack.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/property/LocalPropertyStack.java b/src/main/org/apache/tools/ant/property/LocalPropertyStack.java
index 482f28c..4babf29 100644
--- a/src/main/org/apache/tools/ant/property/LocalPropertyStack.java
+++ b/src/main/org/apache/tools/ant/property/LocalPropertyStack.java
@@ -17,6 +17,7 @@
  */
 package org.apache.tools.ant.property;
 
+import java.util.Deque;
 import java.util.LinkedList;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -29,7 +30,7 @@ import org.apache.tools.ant.PropertyHelper;
  * @since Ant 1.8.0
  */
 public class LocalPropertyStack {
-    private final LinkedList<Map<String, Object>> stack = new LinkedList<Map<String, Object>>();
+    private final Deque<Map<String, Object>> stack = new LinkedList<>();
     private final Object LOCK = new Object();
 
     // --------------------------------------------------

http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/property/NullReturn.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/property/NullReturn.java b/src/main/org/apache/tools/ant/property/NullReturn.java
index 067aa9f..9b90bf2 100644
--- a/src/main/org/apache/tools/ant/property/NullReturn.java
+++ b/src/main/org/apache/tools/ant/property/NullReturn.java
@@ -32,6 +32,7 @@ public final class NullReturn {
     /**
      * {@inheritDoc}
      */
+    @Override
     public String toString() {
         return "null";
     }

http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/property/ParseProperties.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/property/ParseProperties.java b/src/main/org/apache/tools/ant/property/ParseProperties.java
index f03f966..6f08b74 100644
--- a/src/main/org/apache/tools/ant/property/ParseProperties.java
+++ b/src/main/org/apache/tools/ant/property/ParseProperties.java
@@ -19,6 +19,7 @@ package org.apache.tools.ant.property;
 
 import java.text.ParsePosition;
 import java.util.Collection;
+import java.util.Objects;
 
 import org.apache.tools.ant.Project;
 
@@ -49,6 +50,7 @@ public class ParseProperties implements ParseNextProperty {
      * Get the project.
      * @return the current Ant project.
      */
+    @Override
     public Project getProject() {
         return project;
     }
@@ -90,7 +92,7 @@ public class ParseProperties implements ParseNextProperty {
      *         <code>null</code> if the original string is <code>null</code>.
      */
     public Object parseProperties(String value) {
-        if (value == null || "".equals(value)) {
+        if (value == null || value.isEmpty()) {
             return value;
         }
         final int len = value.length();
@@ -99,7 +101,7 @@ public class ParseProperties implements ParseNextProperty {
         if (o != null && pos.getIndex() >= len) {
             return o;
         }
-        StringBuffer sb = new StringBuffer(len * 2);
+        StringBuilder sb = new StringBuilder(len * 2);
         if (o == null) {
             sb.append(value.charAt(pos.getIndex()));
             pos.setIndex(pos.getIndex() + 1);
@@ -157,6 +159,7 @@ public class ParseProperties implements ParseNextProperty {
      * property doesn't expand to a value, the property's name is
      * returned.
      */
+    @Override
     public Object parseNextProperty(String value, ParsePosition pos) {
         final int start = pos.getIndex();
 
@@ -183,14 +186,9 @@ public class ParseProperties implements ParseNextProperty {
     }
 
     private String parsePropertyName(String value, ParsePosition pos) {
-        for (PropertyExpander propertyExpander : expanders) {
-            String propertyName = propertyExpander.parsePropertyName(value, pos, this);
-            if (propertyName == null) {
-                continue;
-            }
-            return propertyName;
-        }
-        return null;
+        return expanders.stream()
+            .map(xp -> xp.parsePropertyName(value, pos, this))
+            .filter(Objects::nonNull).findFirst().orElse(null);
     }
 
     private Object getProperty(String propertyName) {

http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/property/ResolvePropertyMap.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/property/ResolvePropertyMap.java b/src/main/org/apache/tools/ant/property/ResolvePropertyMap.java
index 5bdd354..1554ec3 100644
--- a/src/main/org/apache/tools/ant/property/ResolvePropertyMap.java
+++ b/src/main/org/apache/tools/ant/property/ResolvePropertyMap.java
@@ -30,7 +30,7 @@ import org.apache.tools.ant.Project;
  * @since Ant 1.8.0
  */
 public class ResolvePropertyMap implements GetProperty {
-    private final Set<String> seen = new HashSet<String>();
+    private final Set<String> seen = new HashSet<>();
     private final ParseProperties parseProperties;
     private final GetProperty master;
     private Map<String, Object> map;
@@ -58,10 +58,11 @@ public class ResolvePropertyMap implements GetProperty {
      * @param name name of the property.
      * @return the property value, or null for no match or for name being null.
      */
+    @Override
     public Object getProperty(String name) {
         if (seen.contains(name)) {
-            throw new BuildException(
-                "Property " + name + " was circularly " + "defined.");
+            throw new BuildException("Property %s was circularly defined.",
+                name);
         }
 
         try {
@@ -110,6 +111,7 @@ public class ResolvePropertyMap implements GetProperty {
      * @param map the map to resolve properties in.
      * @deprecated since Ant 1.8.2, use the three-arg method instead.
      */
+    @Deprecated
     public void resolveAllProperties(Map<String, Object> map) {
         resolveAllProperties(map, null, false);
     }
@@ -121,6 +123,7 @@ public class ResolvePropertyMap implements GetProperty {
      * will finally receive - may be null.
      * @deprecated since Ant 1.8.2, use the three-arg method instead.
      */
+    @Deprecated
     public void resolveAllProperties(Map<String, Object> map, String prefix) {
         resolveAllProperties(map, null, false);
     }


Re: [32/34] ant git commit: java 5-8

Posted by Stefan Bodewig <bo...@apache.org>.
On 2017-04-20, Matt Benson wrote:

> On Thu, Apr 20, 2017 at 2:48 AM, Stefan Bodewig <bo...@apache.org> wrote:

>> Wouldn't we end up with a null InputStream and an exception being thrown
>> later on?

> In my debugging the XML parser allowed the null InputStream and took it
> upon itself to go find the named resource.

Ah, because of the SYSTEM id, I see.

>> so the current code is certainly wrong. I'll try to dig deeper into this
>> the coming days unless anybody else beats me to it.

> By "current" do you mean the code that increments past the ':' but not
> the '/', i.e. until I fixed said bug?

Right, the code in master has been fixed but the one in 1.9.x is still
broken. Apart from porting your fix I'd like to grep through the code
base to look for similar errors and maybe try to come up with a
test. Given the XML parser may be doing the job correctly anyway,
writing a test may not be possible.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: [32/34] ant git commit: java 5-8

Posted by Matt Benson <gu...@gmail.com>.
On Thu, Apr 20, 2017 at 2:48 AM, Stefan Bodewig <bo...@apache.org> wrote:

> On 2017-04-19, Matt Benson wrote:
>
> > I had forgotten about this. When testing my other changes I noted that no
> > InputStream was returned here, due to the requested entry name including
> > the leading slash from the jar resource URL; the jar entries encountered
> > during testing, at least, lacked the leading slash.
>
> So this has never worked and nobody has noticed so far, strange.
>
> > Due to this the actual reading of the resource was deferred to the XML
> > parser. Skipping the slash fixed this issue for me and seemed
> > anecdotally to decrease the amount of time needed to run the
> > tests.
>
> Wouldn't we end up with a null InputStream and an exception being thrown
> later on?
>
> In my debugging the XML parser allowed the null InputStream and took it
upon itself to go find the named resource. This caused a weird exception
that somehow coincided with the changes to Path and Union to use the Java 8
Stream APIs, prompting me to find and fix this bug.


> > You of course know much more about the file format than I; I have been
> > unable to find a definitive resource that confirms that jar file
> > entries should always lack a leading separator.
>
> A leading slash would violate the ZIP spec
>
> https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
>
>        4.4.17.1 The name of the file, with optional relative path.
>        The path stored MUST not contain a drive or
>        device letter, or a leading slash. ...
>
> so the current code is certainly wrong. I'll try to dig deeper into this
> the coming days unless anybody else beats me to it.
>
> By "current" do you mean the code that increments past the ':' but not the
'/', i.e. until I fixed said bug?


> Many thanks
>
> Not at all, thank you!

Matt


>         Stefan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>

Re: [32/34] ant git commit: java 5-8

Posted by Stefan Bodewig <bo...@apache.org>.
On 2017-04-19, Matt Benson wrote:

> I had forgotten about this. When testing my other changes I noted that no
> InputStream was returned here, due to the requested entry name including
> the leading slash from the jar resource URL; the jar entries encountered
> during testing, at least, lacked the leading slash.

So this has never worked and nobody has noticed so far, strange.

> Due to this the actual reading of the resource was deferred to the XML
> parser. Skipping the slash fixed this issue for me and seemed
> anecdotally to decrease the amount of time needed to run the
> tests.

Wouldn't we end up with a null InputStream and an exception being thrown
later on?

> You of course know much more about the file format than I; I have been
> unable to find a definitive resource that confirms that jar file
> entries should always lack a leading separator.

A leading slash would violate the ZIP spec

https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT

       4.4.17.1 The name of the file, with optional relative path.
       The path stored MUST not contain a drive or
       device letter, or a leading slash. ...

so the current code is certainly wrong. I'll try to dig deeper into this
the coming days unless anybody else beats me to it.

Many thanks

        Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: [32/34] ant git commit: java 5-8

Posted by Matt Benson <gu...@gmail.com>.
Hi Stefan,
  I had forgotten about this. When testing my other changes I noted that no
InputStream was returned here, due to the requested entry name including
the leading slash from the jar resource URL; the jar entries encountered
during testing, at least, lacked the leading slash. Due to this the actual
reading of the resource was deferred to the XML parser. Skipping the slash
fixed this issue for me and seemed anecdotally to decrease the amount of
time needed to run the tests. You of course know much more about the file
format than I; I have been unable to find a definitive resource that
confirms that jar file entries should always lack a leading separator.

Matt

On Wed, Apr 19, 2017 at 7:58 AM, Stefan Bodewig <bo...@apache.org> wrote:

> Matt,
>
> something I overlooked on my first pass
>
> On 2017-04-13, <mb...@apache.org> wrote:
>
> > http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/
> src/main/org/apache/tools/ant/helper/ProjectHelper2.java
> > @@ -256,7 +259,7 @@ public class ProjectHelper2 extends ProjectHelper {
> >                      zf = new ZipFile(org.apache.tools.ant.
> launch.Locator
> >                                       .fromJarURI(uri), "UTF-8");
> >                      inputStream =
> > -                        zf.getInputStream(zf.getEntry(uri.substring(pling
> + 1)));
> > +                        zf.getInputStream(zf.getEntry(uri.substring(pling
> + 2)));
>
> why did you change the offset from 1 to 2? Doesn't look right to me but
> if it is we should probably change it for 1.9.x as well.
>
> Stefan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>

Re: [32/34] ant git commit: java 5-8

Posted by Stefan Bodewig <bo...@apache.org>.
Matt,

something I overlooked on my first pass

On 2017-04-13, <mb...@apache.org> wrote:

> http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
> @@ -256,7 +259,7 @@ public class ProjectHelper2 extends ProjectHelper {
>                      zf = new ZipFile(org.apache.tools.ant.launch.Locator
>                                       .fromJarURI(uri), "UTF-8");
>                      inputStream =
> -                        zf.getInputStream(zf.getEntry(uri.substring(pling + 1)));
> +                        zf.getInputStream(zf.getEntry(uri.substring(pling + 2)));

why did you change the offset from 1 to 2? Doesn't look right to me but
if it is we should probably change it for 1.9.x as well.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org