avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ieme...@apache.org
Subject [avro] 01/01: Multiple static analysis fixes and code modernization
Date Mon, 18 Mar 2019 09:00:57 GMT
This is an automated email from the ASF dual-hosted git repository.

iemejia pushed a commit to branch fix-warnings2
in repository https://gitbox.apache.org/repos/asf/avro.git

commit 1119b6eb5b92730b27e9798793bc67f192591c15
Author: Ismaël Mejía <iemejia@gmail.com>
AuthorDate: Tue Mar 12 21:36:40 2019 +0100

    Multiple static analysis fixes and code modernization
---
 .../main/java/org/apache/avro/JsonProperties.java  |   4 +-
 .../main/java/org/apache/avro/LogicalTypes.java    |   4 +-
 .../avro/src/main/java/org/apache/avro/Schema.java |  56 +++------
 .../java/org/apache/avro/SchemaCompatibility.java  |  26 ++--
 .../src/main/java/org/apache/avro/ValidateAll.java |   6 +-
 .../src/main/java/org/apache/avro/data/Json.java   |   5 +-
 .../org/apache/avro/data/RecordBuilderBase.java    |  11 +-
 .../main/java/org/apache/avro/file/BZip2Codec.java |   4 +-
 .../org/apache/avro/file/DataFileReader12.java     |   4 +-
 .../java/org/apache/avro/file/DataFileWriter.java  |  14 +--
 .../java/org/apache/avro/file/SnappyCodec.java     |   4 +-
 .../java/org/apache/avro/file/ZstandardCodec.java  |   4 +-
 .../apache/avro/generic/GenericDatumReader.java    |  15 +--
 .../apache/avro/generic/GenericRecordBuilder.java  |   7 +-
 .../main/java/org/apache/avro/io/BinaryData.java   |   8 +-
 .../java/org/apache/avro/io/BinaryDecoder.java     |   1 -
 .../java/org/apache/avro/io/ResolvingDecoder.java  |   2 +-
 .../java/org/apache/avro/io/parsing/Symbol.java    |   2 +-
 .../apache/avro/message/BinaryMessageDecoder.java  |  18 +--
 .../org/apache/avro/message/MessageDecoder.java    |  14 +--
 .../org/apache/avro/message/RawMessageDecoder.java |   8 +-
 .../org/apache/avro/message/RawMessageEncoder.java |  12 +-
 .../org/apache/avro/reflect/ArrayAccessor.java     |  28 ++---
 .../java/org/apache/avro/reflect/ReflectData.java  |  14 +--
 .../apache/avro/reflect/ReflectDatumWriter.java    |   4 +-
 .../src/main/java/org/apache/avro/util/Utf8.java   |   2 +-
 .../org/apache/avro/util/WeakIdentityHashMap.java  |   5 +-
 .../java/org/apache/avro/ByteBufferRecord.java     |   3 +-
 .../java/org/apache/avro/FooBarSpecificRecord.java |   6 +-
 .../org/apache/avro/TestCircularReferences.java    |  40 +-----
 .../test/java/org/apache/avro/TestDataFile.java    |  57 +++------
 .../java/org/apache/avro/TestDataFileReflect.java  |   6 +-
 .../test/java/org/apache/avro/TestLogicalType.java |  65 ++++------
 .../java/org/apache/avro/TestNestedRecords.java    |   4 +-
 .../java/org/apache/avro/TestSchemaBuilder.java    |   8 +-
 .../org/apache/avro/TestSchemaCompatibility.java   |  12 +-
 .../TestSchemaCompatibilityFixedSizeMismatch.java  |   3 -
 .../TestSchemaCompatibilityMissingEnumSymbols.java |   3 -
 .../TestSchemaCompatibilityMissingUnionBranch.java |  33 +++--
 .../avro/TestSchemaCompatibilityNameMismatch.java  |   2 -
 ...ompatibilityReaderFieldMissingDefaultValue.java |   2 -
 .../avro/TestSchemaCompatibilityTypeMismatch.java  |   2 -
 .../org/apache/avro/TestSchemaNormalization.java   |   8 +-
 .../java/org/apache/avro/TestSchemaValidation.java |  11 +-
 .../apache/avro/data/RecordBuilderBaseTest.java    |  12 +-
 .../avro/file/TestIOExceptionDuringWrite.java      |   5 +-
 .../avro/file/TestSeekableByteArrayInput.java      |  27 ++--
 .../org/apache/avro/file/codec/CustomCodec.java    |   8 +-
 .../org/apache/avro/generic/TestGenericData.java   |  64 +++++-----
 .../avro/generic/TestGenericDatumWriter.java       |  18 +--
 .../avro/generic/TestGenericLogicalTypes.java      |  22 +---
 .../avro/generic/TestGenericRecordBuilder.java     |   7 +-
 .../java/org/apache/avro/io/TestBinaryDecoder.java |   3 +-
 .../java/org/apache/avro/io/TestBlockingIO.java    |   1 -
 .../java/org/apache/avro/io/TestValidatingIO.java  |   6 +-
 .../io/parsing/TestResolvingGrammarGenerator.java  |  10 +-
 .../io/parsing/TestResolvingGrammarGenerator2.java |   3 +-
 .../apache/avro/reflect/TestNonStringMapKeys.java  |  24 ++--
 .../java/org/apache/avro/reflect/TestReflect.java  |  17 +--
 .../avro/reflect/TestReflectDatumReader.java       |  11 +-
 .../avro/reflect/TestReflectLogicalTypes.java      |  31 ++---
 .../org/apache/avro/compiler/schema/Schemas.java   |  18 +--
 .../avro/compiler/specific/ProtocolTask.java       |  11 +-
 .../avro/compiler/specific/SpecificCompiler.java   |   6 +-
 .../org/apache/avro/compiler/idl/TestCycle.java    |   3 +-
 .../compiler/specific/TestSpecificCompiler.java    |   2 +-
 .../org/apache/avro/grpc/ServiceDescriptor.java    |   3 +-
 .../org/apache/avro/grpc/TestAvroProtocolGrpc.java |   8 +-
 .../org/apache/avro/ipc/jetty/TestBulkData.java    |   4 +-
 .../org/apache/avro/ipc/netty/NettyServer.java     |  29 ++---
 .../apache/avro/ipc/netty/NettyTransceiver.java    |  21 ++--
 .../apache/avro/ipc/netty/NettyTransportCodec.java |   2 +-
 .../netty/NettyTransceiverWhenFailsToConnect.java  |  42 +++----
 .../ipc/netty/TestNettyServerWithCallbacks.java    |  61 ++++-----
 .../netty/TestNettyTransceiverWhenServerStops.java |  25 ++--
 .../java/org/apache/avro/ipc/HttpTransceiver.java  |  10 +-
 .../org/apache/avro/ipc/SaslSocketTransceiver.java |   2 +-
 .../java/org/apache/avro/ipc/SocketServer.java     |   5 +-
 .../avro/ipc/specific/SpecificRequestor.java       | 101 ++++++++-------
 .../avro/ipc/specific/SpecificResponder.java       |   4 +-
 .../org/apache/avro/ipc/stats/StatsServlet.java    |   6 -
 .../src/test/java/org/apache/avro/TestCompare.java |  20 +--
 .../java/org/apache/avro/TestDataFileSpecific.java |   1 -
 .../java/org/apache/avro/TestProtocolGeneric.java  |  22 ++--
 .../org/apache/avro/TestProtocolReflectMeta.java   |   2 +-
 .../java/org/apache/avro/TestProtocolSpecific.java |   9 +-
 .../src/test/java/org/apache/avro/TestSchema.java  |   6 +-
 .../compiler/specific/TestSpecificCompiler.java    |   3 +-
 .../java/org/apache/avro/generic/TestDeepCopy.java |   8 +-
 .../ipc/src/test/java/org/apache/avro/io/Perf.java | 136 ++++++++++-----------
 .../org/apache/avro/ipc/TestSaslAnonymous.java     |   6 +-
 .../org/apache/avro/ipc/stats/TestHistogram.java   |  12 +-
 .../apache/avro/message/TestCustomSchemaStore.java |   2 +-
 .../avro/specific/TestSpecificBuilderTree.java     |   1 -
 .../org/apache/avro/specific/TestSpecificData.java |   7 +-
 .../avro/specific/TestSpecificDatumReader.java     |   3 +-
 .../avro/specific/TestSpecificRecordBuilder.java   |  16 +--
 .../avro/hadoop/file/SortedKeyValueFile.java       |  35 +++---
 .../apache/avro/hadoop/io/AvroSequenceFile.java    |   8 +-
 .../apache/avro/hadoop/io/AvroSerialization.java   |   2 +-
 .../hadoop/util/AvroCharSequenceComparator.java    |   2 +-
 .../main/java/org/apache/avro/mapred/AvroJob.java  |   2 +-
 .../java/org/apache/avro/mapred/AvroWrapper.java   |   7 +-
 .../apache/avro/mapred/DelegatingInputFormat.java  |   7 +-
 .../src/main/java/org/apache/avro/mapred/Pair.java |   6 +-
 .../org/apache/avro/mapred/SequenceFileReader.java |  44 ++-----
 .../org/apache/avro/mapred/TaggedInputSplit.java   |   2 +-
 .../avro/mapred/tether/TetherOutputService.java    |   4 +-
 .../apache/avro/mapred/tether/TetheredProcess.java |   4 +-
 .../apache/avro/mapreduce/AvroMultipleOutputs.java |   4 +-
 .../avro/hadoop/file/TestSortedKeyValueFile.java   |  65 ++--------
 .../hadoop/io/TestAvroDatumConverterFactory.java   |   6 +-
 .../org/apache/avro/mapred/TestAvroTextSort.java   |   3 -
 .../org/apache/avro/mapred/TestGenericJob.java     |   4 -
 .../avro/mapred/tether/TestWordCountTether.java    |   1 -
 .../org/apache/avro/mapred/tether/TetherTask.java  |   7 +-
 .../avro/mapred/tether/TetherTaskRunner.java       |   7 +-
 .../avro/mapreduce/TestAvroMultipleOutputs.java    |   5 +-
 .../org/apache/avro/mapreduce/TestWordCount.java   |   7 +-
 .../org/apache/avro/mojo/AbstractAvroMojo.java     |   2 +-
 .../java/org/apache/avro/mojo/IDLProtocolMojo.java |   6 +-
 .../main/java/org/apache/avro/mojo/InduceMojo.java |   2 +-
 .../java/org/apache/avro/mojo/ProtocolMojo.java    |   4 +-
 .../main/java/org/apache/avro/mojo/SchemaMojo.java |   4 +-
 .../java/org/apache/avro/mojo/TestInduceMojo.java  |   4 +-
 .../org/apache/avro/protobuf/ProtobufData.java     |  16 +--
 .../test/java/org/apache/avro/protobuf/Test.java   |  97 +++++++--------
 .../java/org/apache/avro/thrift/test/Error.java    |   5 +-
 .../test/java/org/apache/avro/thrift/test/Foo.java |  46 +++----
 .../java/org/apache/avro/thrift/test/Nested.java   |   7 +-
 .../java/org/apache/avro/thrift/test/Test.java     |  53 ++++----
 .../org/apache/avro/tool/DataFileReadTool.java     |   9 +-
 .../org/apache/avro/tool/DataFileRepairTool.java   |  11 +-
 .../main/java/org/apache/avro/tool/IdlTool.java    |   2 +-
 .../src/main/java/org/apache/avro/tool/Main.java   |  10 +-
 .../java/org/apache/avro/tool/RpcProtocolTool.java |  17 +--
 .../java/org/apache/avro/tool/RpcReceiveTool.java  |  15 +--
 .../main/java/org/apache/avro/tool/TetherTool.java |   6 +-
 .../org/apache/avro/tool/TrevniMetadataTool.java   |   3 +-
 .../org/apache/avro/tool/TrevniToJsonTool.java     |   5 +-
 .../src/main/java/org/apache/avro/tool/Util.java   |   8 +-
 .../java/org/apache/avro/tool/TestCatTool.java     |   2 +-
 .../apache/avro/tool/TestCreateRandomFileTool.java |  29 ++---
 .../apache/avro/tool/TestDataFileRepairTool.java   |   1 -
 .../java/org/apache/avro/tool/TestRecodecTool.java |   5 +-
 .../org/apache/avro/tool/TestRpcProtocolTool.java  |   3 +-
 .../java/org/apache/avro/tool/TestTetherTool.java  |   1 -
 .../org/apache/trevni/avro/AvroColumnReader.java   |  16 +--
 .../org/apache/trevni/avro/AvroColumnator.java     |   6 +-
 .../apache/trevni/avro/AvroTrevniOutputFormat.java |   5 +-
 .../avro/mapreduce/AvroTrevniRecordWriterBase.java |  12 +-
 .../java/org/apache/trevni/avro/TestCases.java     |  13 +-
 .../java/org/apache/trevni/avro/WordCountUtil.java |   4 +-
 .../main/java/org/apache/trevni/BZip2Codec.java    |  12 +-
 .../java/org/apache/trevni/ColumnFileWriter.java   |  12 +-
 .../main/java/org/apache/trevni/InputBuffer.java   |   2 +-
 .../java/org/apache/trevni/TestBZip2Codec.java     |   4 +-
 lang/java/trevni/doc/pom.xml                       |   1 -
 lang/java/trevni/pom.xml                           |   1 -
 159 files changed, 763 insertions(+), 1363 deletions(-)

diff --git a/lang/java/avro/src/main/java/org/apache/avro/JsonProperties.java b/lang/java/avro/src/main/java/org/apache/avro/JsonProperties.java
index e18e05a..fed9b8f 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/JsonProperties.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/JsonProperties.java
@@ -145,12 +145,12 @@ public abstract class JsonProperties {
   // only modifier
   private ConcurrentMap<String,JsonNode> props = new ConcurrentHashMap<String,JsonNode>() {
     private static final long serialVersionUID = 1L;
-    private Queue<MapEntry<String, JsonNode>> propOrder = new ConcurrentLinkedQueue<MapEntry<String, JsonNode>>();
+    private Queue<MapEntry<String, JsonNode>> propOrder = new ConcurrentLinkedQueue<>();
     @Override
     public JsonNode putIfAbsent(String key,  JsonNode value) {
       JsonNode r = super.putIfAbsent(key, value);
       if (r == null) {
-        propOrder.add(new MapEntry<String, JsonNode>(key, value));
+        propOrder.add(new MapEntry<>(key, value));
       }
       return r;
     }
diff --git a/lang/java/avro/src/main/java/org/apache/avro/LogicalTypes.java b/lang/java/avro/src/main/java/org/apache/avro/LogicalTypes.java
index d8f50e2..ad345f9 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/LogicalTypes.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/LogicalTypes.java
@@ -280,9 +280,7 @@ public class LogicalTypes {
       Decimal decimal = (Decimal) o;
 
       if (precision != decimal.precision) return false;
-      if (scale != decimal.scale) return false;
-
-      return true;
+      return scale == decimal.scale;
     }
 
     @Override
diff --git a/lang/java/avro/src/main/java/org/apache/avro/Schema.java b/lang/java/avro/src/main/java/org/apache/avro/Schema.java
index 06e5fca..03e3ec4 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/Schema.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/Schema.java
@@ -17,37 +17,36 @@
  */
 package org.apache.avro;
 
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.DoubleNode;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.StringWriter;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.IdentityHashMap;
+import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
-
 import org.apache.avro.util.internal.Accessor;
 import org.apache.avro.util.internal.Accessor.FieldAccessor;
 import org.apache.avro.util.internal.JacksonUtils;
 
-import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.DoubleNode;
-
 /** An abstract data type.
  * <p>A schema may be one of:
  * <ul>
@@ -477,7 +476,7 @@ public abstract class Schema extends JsonProperties {
       this(field.name, schema, field.doc, field.defaultValue, field.order);
       putAll(field);
       if (field.aliases != null)
-        aliases = new LinkedHashSet<String>(field.aliases);
+        aliases = new LinkedHashSet<>(field.aliases);
     }
     /**
      * @param defaultValue the default value for this field specified using the mapping
@@ -576,7 +575,7 @@ public abstract class Schema extends JsonProperties {
       if (o == this) return true;
       if (!(o instanceof Name)) return false;
       Name that = (Name)o;
-      return full==null ? that.full==null : full.equals(that.full);
+      return Objects.equals(full, that.full);
     }
     @Override public int hashCode() {
       return full==null ? 0 : full.hashCode();
@@ -672,12 +671,8 @@ public abstract class Schema extends JsonProperties {
     }
   }
 
-  private static final ThreadLocal<Set> SEEN_EQUALS = new ThreadLocal<Set>() {
-    @Override protected Set initialValue() { return new HashSet(); }
-  };
-  private static final ThreadLocal<Map> SEEN_HASHCODE = new ThreadLocal<Map>() {
-    @Override protected Map initialValue() { return new IdentityHashMap(); }
-  };
+  private static final ThreadLocal<Set> SEEN_EQUALS = ThreadLocal.withInitial(HashSet::new);
+  private static final ThreadLocal<Map> SEEN_HASHCODE = ThreadLocal.withInitial(IdentityHashMap::new);
 
   @SuppressWarnings(value="unchecked")
   private static class RecordSchema extends NamedSchema {
@@ -1196,10 +1191,10 @@ public abstract class Schema extends JsonProperties {
       if (primitive != null) {
         return Schema.create(primitive);
       }
-      Name name = new Name((String) o, space);
+      Name name = new Name(o, space);
       if (!containsKey(name)) {
         // if not in default try anonymous
-        name = new Name((String) o, "");
+        name = new Name(o, "");
       }
       return super.get(name);
     }
@@ -1219,11 +1214,7 @@ public abstract class Schema extends JsonProperties {
   }
 
   private static ThreadLocal<Boolean> validateNames
-    = new ThreadLocal<Boolean>() {
-    @Override protected Boolean initialValue() {
-      return true;
-    }
-  };
+    = ThreadLocal.withInitial(() -> true);
 
   private static String validateName(String name) {
     if (!validateNames.get()) return name;        // not validating names
@@ -1242,11 +1233,7 @@ public abstract class Schema extends JsonProperties {
   }
 
   private static final ThreadLocal<Boolean> VALIDATE_DEFAULTS
-    = new ThreadLocal<Boolean>() {
-    @Override protected Boolean initialValue() {
-      return true;
-    }
-  };
+    = ThreadLocal.withInitial(() -> true);
 
   private static JsonNode validateDefault(String fieldName, Schema schema,
                                           JsonNode defaultValue) {
@@ -1599,10 +1586,7 @@ public abstract class Schema extends JsonProperties {
       for (Field field : schema.getFields()) {
         if (field.aliases != null)
           for (String fieldAlias : field.aliases) {
-            Map<String,String> recordAliases = fieldAliases.get(record.name);
-            if (recordAliases == null)
-              fieldAliases.put(record.name,
-                               recordAliases = new HashMap<>());
+            Map<String, String> recordAliases = fieldAliases.computeIfAbsent(record.name, k -> new HashMap<>());
             recordAliases.put(fieldAlias, field.name);
           }
         getAliases(field.schema, seen, aliases, fieldAliases);
diff --git a/lang/java/avro/src/main/java/org/apache/avro/SchemaCompatibility.java b/lang/java/avro/src/main/java/org/apache/avro/SchemaCompatibility.java
index 4b9c813..fb9e020 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/SchemaCompatibility.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/SchemaCompatibility.java
@@ -25,9 +25,9 @@ import java.util.Deque;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 import java.util.TreeSet;
-
 import org.apache.avro.Schema.Field;
 import org.apache.avro.Schema.Type;
 import org.slf4j.Logger;
@@ -105,10 +105,7 @@ public class SchemaCompatibility {
       return true;
     }
     // Apply reader aliases:
-    if (reader.getAliases().contains(writerFullName)) {
-      return true;
-    }
-    return false;
+    return reader.getAliases().contains(writerFullName);
   }
 
   /**
@@ -546,9 +543,9 @@ public class SchemaCompatibility {
     private final List<Incompatibility> mIncompatibilities;
     // cached objects for stateless details
     private static final SchemaCompatibilityResult COMPATIBLE = new SchemaCompatibilityResult(
-        SchemaCompatibilityType.COMPATIBLE, Collections.<Incompatibility> emptyList());
+        SchemaCompatibilityType.COMPATIBLE, Collections.emptyList());
     private static final SchemaCompatibilityResult RECURSION_IN_PROGRESS = new SchemaCompatibilityResult(
-        SchemaCompatibilityType.RECURSION_IN_PROGRESS, Collections.<Incompatibility> emptyList());
+        SchemaCompatibilityType.RECURSION_IN_PROGRESS, Collections.emptyList());
 
     private SchemaCompatibilityResult(SchemaCompatibilityType compatibilityType,
         List<Incompatibility> incompatibilities) {
@@ -634,9 +631,7 @@ public class SchemaCompatibility {
           return false;
       } else if (!mIncompatibilities.equals(other.mIncompatibilities))
         return false;
-      if (mCompatibilityType != other.mCompatibilityType)
-        return false;
-      return true;
+      return mCompatibilityType == other.mCompatibilityType;
     }
 
     /** {@inheritDoc} */
@@ -776,13 +771,8 @@ public class SchemaCompatibility {
         return false;
       }
       if (mLocation == null) {
-        if (other.mLocation != null) {
-          return false;
-        }
-      } else if (!mLocation.equals(other.mLocation)) {
-        return false;
-      }
-      return true;
+        return other.mLocation == null;
+      } else return mLocation.equals(other.mLocation);
     }
 
     /** {@inheritDoc} */
@@ -905,7 +895,7 @@ public class SchemaCompatibility {
 
   /** Borrowed from Guava's Objects.equal(a, b) */
   private static boolean objectsEqual(Object obj1, Object obj2) {
-    return (obj1 == obj2) || ((obj1 != null) && obj1.equals(obj2));
+    return Objects.equals(obj1, obj2);
   }
 
   private static List<String> asList(Deque<String> deque) {
diff --git a/lang/java/avro/src/main/java/org/apache/avro/ValidateAll.java b/lang/java/avro/src/main/java/org/apache/avro/ValidateAll.java
index 2377bd7..407a51d 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/ValidateAll.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/ValidateAll.java
@@ -18,8 +18,6 @@
 
 package org.apache.avro;
 
-import java.util.Iterator;
-
 /**
  * <p>
  * A {@link SchemaValidator} for validating the provided schema against all
@@ -45,9 +43,7 @@ public final class ValidateAll implements SchemaValidator {
   @Override
   public void validate(Schema toValidate, Iterable<Schema> schemasInOrder)
       throws SchemaValidationException {
-    Iterator<Schema> schemas = schemasInOrder.iterator();
-    while (schemas.hasNext()) {
-      Schema existing = schemas.next();
+    for (Schema existing : schemasInOrder) {
       strategy.validate(toValidate, existing);
     }
   }
diff --git a/lang/java/avro/src/main/java/org/apache/avro/data/Json.java b/lang/java/avro/src/main/java/org/apache/avro/data/Json.java
index 71b1710..94fc048 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/data/Json.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/data/Json.java
@@ -54,11 +54,8 @@ public class Json {
   public static final Schema SCHEMA;
   static {
     try {
-      InputStream in = Json.class.getResourceAsStream("/org/apache/avro/data/Json.avsc");
-      try {
+      try (InputStream in = Json.class.getResourceAsStream("/org/apache/avro/data/Json.avsc")) {
         SCHEMA = new Schema.Parser().parse(in);
-      } finally {
-        in.close();
       }
     } catch (IOException e) {
       throw new AvroRuntimeException(e);
diff --git a/lang/java/avro/src/main/java/org/apache/avro/data/RecordBuilderBase.java b/lang/java/avro/src/main/java/org/apache/avro/data/RecordBuilderBase.java
index 626ab19..99f42d8 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/data/RecordBuilderBase.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/data/RecordBuilderBase.java
@@ -80,10 +80,8 @@ public abstract class RecordBuilderBase<T extends IndexedRecord>
    */
   protected void validate(Field field, Object value) {
     if (isValidValue(field, value)) {
-      return;
     }
     else if (field.defaultVal() != null) {
-      return;
     }
     else {
       throw new AvroRuntimeException(
@@ -157,10 +155,9 @@ public abstract class RecordBuilderBase<T extends IndexedRecord>
     if (!Arrays.equals(fieldSetFlags, other.fieldSetFlags))
       return false;
     if (schema == null) {
-      if (other.schema != null)
-        return false;
-    } else if (!schema.equals(other.schema))
-      return false;
-    return true;
+      return other.schema == null;
+    } else {
+      return schema.equals(other.schema);
+    }
   }
 }
diff --git a/lang/java/avro/src/main/java/org/apache/avro/file/BZip2Codec.java b/lang/java/avro/src/main/java/org/apache/avro/file/BZip2Codec.java
index 1d1f4ed..e9a27ac 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/file/BZip2Codec.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/file/BZip2Codec.java
@@ -75,9 +75,7 @@ public class BZip2Codec extends Codec {
   public boolean equals(Object obj) {
     if (this == obj)
       return true;
-    if (obj == null || obj.getClass() != getClass())
-      return false;
-    return true;
+    return obj != null && obj.getClass() == getClass();
   }
 
   //get and initialize the output buffer for use.
diff --git a/lang/java/avro/src/main/java/org/apache/avro/file/DataFileReader12.java b/lang/java/avro/src/main/java/org/apache/avro/file/DataFileReader12.java
index efee14a..115ef71 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/file/DataFileReader12.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/file/DataFileReader12.java
@@ -56,7 +56,6 @@ public class DataFileReader12<D> implements FileReader<D>, Closeable {
 
   private Map<String,byte[]> meta = new HashMap<>();
 
-  private long count;                           // # entries in file
   private long blockCount;                      // # entries in block
   private long blockStart;
   private byte[] sync = new byte[SYNC_SIZE];
@@ -90,7 +89,8 @@ public class DataFileReader12<D> implements FileReader<D>, Closeable {
     }
 
     this.sync = getMeta(SYNC);
-    this.count = getMetaLong(COUNT);
+    // # entries in file
+    long count = getMetaLong(COUNT);
     String codec = getMetaString(CODEC);
     if (codec != null && ! codec.equals(NULL_CODEC)) {
       throw new UnknownAvroCodecException("Unknown codec: " + codec);
diff --git a/lang/java/avro/src/main/java/org/apache/avro/file/DataFileWriter.java b/lang/java/avro/src/main/java/org/apache/avro/file/DataFileWriter.java
index 0dc9b06..1d1e536 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/file/DataFileWriter.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/file/DataFileWriter.java
@@ -198,16 +198,11 @@ public class DataFileWriter<D> implements Closeable, Flushable {
 
   /** Open a writer appending to an existing file. */
   public DataFileWriter<D> appendTo(File file) throws IOException {
-    SeekableInput input = null;
-    try {
-      input = new SeekableFileInput(file);
+    try (SeekableInput input = new SeekableFileInput(file)) {
       OutputStream output = new SyncableFileOutputStream(file, true);
       return appendTo(input, output);
-    } finally {
-      if (input != null)
-        input.close();
-      // output does not need to be closed here. It will be closed by invoking close() of this writer.
     }
+    // output does not need to be closed here. It will be closed by invoking close() of this writer.
   }
 
   /** Open a writer appending to an existing file.
@@ -308,12 +303,9 @@ public class DataFileWriter<D> implements Closeable, Flushable {
     int usedBuffer = bufferInUse();
     try {
       dout.write(datum, bufOut);
-    } catch (IOException e) {
+    } catch (IOException | RuntimeException e) {
       resetBufferTo(usedBuffer);
       throw new AppendWriteException(e);
-    } catch (RuntimeException re) {
-      resetBufferTo(usedBuffer);
-      throw new AppendWriteException(re);
     }
     blockCount++;
     writeIfBlockFull();
diff --git a/lang/java/avro/src/main/java/org/apache/avro/file/SnappyCodec.java b/lang/java/avro/src/main/java/org/apache/avro/file/SnappyCodec.java
index 4ffdce7..27915b4 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/file/SnappyCodec.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/file/SnappyCodec.java
@@ -82,8 +82,6 @@ public class SnappyCodec extends Codec {
   public boolean equals(Object obj) {
     if (this == obj)
       return true;
-    if (obj == null || obj.getClass() != getClass())
-      return false;
-    return true;
+    return obj != null && obj.getClass() == getClass();
   }
 }
diff --git a/lang/java/avro/src/main/java/org/apache/avro/file/ZstandardCodec.java b/lang/java/avro/src/main/java/org/apache/avro/file/ZstandardCodec.java
index deea4b8..284f300 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/file/ZstandardCodec.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/file/ZstandardCodec.java
@@ -85,8 +85,6 @@ public class ZstandardCodec extends Codec {
     public boolean equals(Object obj) {
         if (this == obj)
             return true;
-          if (obj == null || obj.getClass() != getClass())
-            return false;
-          return true;
+      return obj != null && obj.getClass() == getClass();
     }
 }
diff --git a/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java b/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java
index 452522a..4ad87c5 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java
@@ -99,12 +99,7 @@ public class GenericDatumReader<D> implements DatumReader<D> {
 
   private static final ThreadLocal<Map<Schema,Map<Schema,ResolvingDecoder>>>
     RESOLVER_CACHE =
-    new ThreadLocal<Map<Schema,Map<Schema,ResolvingDecoder>>>() {
-    @Override
-    protected Map<Schema,Map<Schema,ResolvingDecoder>> initialValue() {
-      return new WeakIdentityHashMap<>();
-    }
-  };
+    ThreadLocal.withInitial(WeakIdentityHashMap::new);
 
   /** Gets a resolving decoder for use by this GenericDatumReader.
    *  Unstable API.
@@ -481,13 +476,7 @@ public class GenericDatumReader<D> implements DatumReader<D> {
         stringCtorCache.put(c, ctor);
       }
       return ctor.newInstance(s);
-    } catch (NoSuchMethodException e) {
-      throw new AvroRuntimeException(e);
-    } catch (InstantiationException e) {
-      throw new AvroRuntimeException(e);
-    } catch (IllegalAccessException e) {
-      throw new AvroRuntimeException(e);
-    } catch (InvocationTargetException e) {
+    } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException e) {
       throw new AvroRuntimeException(e);
     }
   }
diff --git a/lang/java/avro/src/main/java/org/apache/avro/generic/GenericRecordBuilder.java b/lang/java/avro/src/main/java/org/apache/avro/generic/GenericRecordBuilder.java
index a2248bb..45f4a75 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/generic/GenericRecordBuilder.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/generic/GenericRecordBuilder.java
@@ -251,10 +251,7 @@ public class GenericRecordBuilder extends RecordBuilderBase<Record> {
       return false;
     GenericRecordBuilder other = (GenericRecordBuilder) obj;
     if (record == null) {
-      if (other.record != null)
-        return false;
-    } else if (!record.equals(other.record))
-      return false;
-    return true;
+      return other.record == null;
+    } else return record.equals(other.record);
   }
 }
diff --git a/lang/java/avro/src/main/java/org/apache/avro/io/BinaryData.java b/lang/java/avro/src/main/java/org/apache/avro/io/BinaryData.java
index 4bc4d5c..29de304 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/io/BinaryData.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/io/BinaryData.java
@@ -47,9 +47,7 @@ public class BinaryData {
   }                     // no public ctor
 
   private static final ThreadLocal<Decoders> DECODERS
-    = new ThreadLocal<Decoders>() {
-    @Override protected Decoders initialValue() { return new Decoders(); }
-  };
+    = ThreadLocal.withInitial(Decoders::new);
 
   /** Compare binary encoded data.  If equal, return zero.  If greater-than,
    * return 1, if less than return -1. Order is consistent with that of {@link
@@ -192,9 +190,7 @@ public class BinaryData {
   }
 
   private static final ThreadLocal<HashData> HASH_DATA
-    = new ThreadLocal<HashData>() {
-    @Override protected HashData initialValue() { return new HashData(); }
-  };
+    = ThreadLocal.withInitial(HashData::new);
 
   /** Hash binary encoded data. Consistent with {@link
    * org.apache.avro.generic.GenericData#hashCode(Object, Schema)}.*/
diff --git a/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java b/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java
index 74b6fb0..2de70d5 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java
@@ -939,7 +939,6 @@ public class BinaryDecoder extends Decoder {
       decoder.minPos = this.position;
       decoder.limit = this.max;
       this.ba = new BufferAccessor(decoder);
-      return;
     }
 
     @Override
diff --git a/lang/java/avro/src/main/java/org/apache/avro/io/ResolvingDecoder.java b/lang/java/avro/src/main/java/org/apache/avro/io/ResolvingDecoder.java
index 62fc55e..7b3da23 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/io/ResolvingDecoder.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/io/ResolvingDecoder.java
@@ -268,7 +268,7 @@ public class ResolvingDecoder extends ValidatingDecoder {
     if (top.noAdjustments) return n;
     Object o = top.adjustments[n];
     if (o instanceof Integer) {
-      return ((Integer) o).intValue();
+      return (Integer) o;
     } else {
       throw new AvroTypeException((String) o);
     }
diff --git a/lang/java/avro/src/main/java/org/apache/avro/io/parsing/Symbol.java b/lang/java/avro/src/main/java/org/apache/avro/io/parsing/Symbol.java
index 151cf1b..a4a5298 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/io/parsing/Symbol.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/io/parsing/Symbol.java
@@ -396,7 +396,7 @@ public abstract class Symbol {
    * for some inputs.
    */
   public static boolean hasErrors(Symbol symbol) {
-    return hasErrors(symbol, new HashSet<Symbol>());
+    return hasErrors(symbol, new HashSet<>());
   }
 
   private static boolean hasErrors(Symbol symbol, Set<Symbol> visited) {
diff --git a/lang/java/avro/src/main/java/org/apache/avro/message/BinaryMessageDecoder.java b/lang/java/avro/src/main/java/org/apache/avro/message/BinaryMessageDecoder.java
index 9a48646..101851d 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/message/BinaryMessageDecoder.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/message/BinaryMessageDecoder.java
@@ -48,21 +48,13 @@ import java.util.concurrent.ConcurrentHashMap;
 public class BinaryMessageDecoder<D> extends MessageDecoder.BaseDecoder<D> {
 
   private static final ThreadLocal<byte[]> HEADER_BUFFER =
-      new ThreadLocal<byte[]>() {
-        @Override
-        protected byte[] initialValue() {
-          return new byte[10];
-        }
-      };
+    ThreadLocal.withInitial(() -> new byte[10]);
 
   private static final ThreadLocal<ByteBuffer> FP_BUFFER =
-      new ThreadLocal<ByteBuffer>() {
-        @Override
-        protected ByteBuffer initialValue() {
-          byte[] header = HEADER_BUFFER.get();
-          return ByteBuffer.wrap(header).order(ByteOrder.LITTLE_ENDIAN);
-        }
-      };
+    ThreadLocal.withInitial(() -> {
+      byte[] header = HEADER_BUFFER.get();
+      return ByteBuffer.wrap(header).order(ByteOrder.LITTLE_ENDIAN);
+    });
 
   private final GenericData model;
   private final Schema readSchema;
diff --git a/lang/java/avro/src/main/java/org/apache/avro/message/MessageDecoder.java b/lang/java/avro/src/main/java/org/apache/avro/message/MessageDecoder.java
index bc86d12..c97a961 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/message/MessageDecoder.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/message/MessageDecoder.java
@@ -111,20 +111,10 @@ public interface MessageDecoder<D> {
   abstract class BaseDecoder<D> implements MessageDecoder<D> {
 
     private static final ThreadLocal<ReusableByteArrayInputStream>
-        BYTE_ARRAY_IN = new ThreadLocal<ReusableByteArrayInputStream>() {
-          @Override
-          protected ReusableByteArrayInputStream initialValue() {
-            return new ReusableByteArrayInputStream();
-          }
-        };
+        BYTE_ARRAY_IN = ThreadLocal.withInitial(ReusableByteArrayInputStream::new);
 
     private static final ThreadLocal<ReusableByteBufferInputStream>
-        BYTE_BUFFER_IN = new ThreadLocal<ReusableByteBufferInputStream>() {
-          @Override
-          protected ReusableByteBufferInputStream initialValue() {
-            return new ReusableByteBufferInputStream();
-          }
-        };
+        BYTE_BUFFER_IN = ThreadLocal.withInitial(ReusableByteBufferInputStream::new);
 
     @Override
     public D decode(InputStream stream) throws IOException {
diff --git a/lang/java/avro/src/main/java/org/apache/avro/message/RawMessageDecoder.java b/lang/java/avro/src/main/java/org/apache/avro/message/RawMessageDecoder.java
index 1caf715..0b43ee3 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/message/RawMessageDecoder.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/message/RawMessageDecoder.java
@@ -46,8 +46,6 @@ public class RawMessageDecoder<D> extends MessageDecoder.BaseDecoder<D> {
   private static final ThreadLocal<BinaryDecoder> DECODER =
       new ThreadLocal<>();
 
-  private final Schema writeSchema;
-  private final Schema readSchema;
   private final DatumReader<D> reader;
 
   /**
@@ -82,9 +80,9 @@ public class RawMessageDecoder<D> extends MessageDecoder.BaseDecoder<D> {
    */
   public RawMessageDecoder(GenericData model, Schema writeSchema,
                            Schema readSchema) {
-    this.writeSchema = writeSchema;
-    this.readSchema = readSchema;
-    this.reader = model.createDatumReader(this.writeSchema, this.readSchema);
+    Schema writeSchema1 = writeSchema;
+    Schema readSchema1 = readSchema;
+    this.reader = model.createDatumReader(writeSchema1, readSchema1);
   }
 
   @Override
diff --git a/lang/java/avro/src/main/java/org/apache/avro/message/RawMessageEncoder.java b/lang/java/avro/src/main/java/org/apache/avro/message/RawMessageEncoder.java
index d85d20e..7707be0 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/message/RawMessageEncoder.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/message/RawMessageEncoder.java
@@ -38,17 +38,11 @@ import java.nio.ByteBuffer;
 public class RawMessageEncoder<D> implements MessageEncoder<D> {
 
   private static final ThreadLocal<BufferOutputStream> TEMP =
-      new ThreadLocal<BufferOutputStream>() {
-        @Override
-        protected BufferOutputStream initialValue() {
-          return new BufferOutputStream();
-        }
-      };
+    ThreadLocal.withInitial(BufferOutputStream::new);
 
   private static final ThreadLocal<BinaryEncoder> ENCODER =
       new ThreadLocal<>();
 
-  private final Schema writeSchema;
   private final boolean copyOutputBytes;
   private final DatumWriter<D> writer;
 
@@ -86,9 +80,9 @@ public class RawMessageEncoder<D> implements MessageEncoder<D> {
    * @param shouldCopy whether to copy buffers before returning encoded results
    */
   public RawMessageEncoder(GenericData model, Schema schema, boolean shouldCopy) {
-    this.writeSchema = schema;
+    Schema writeSchema = schema;
     this.copyOutputBytes = shouldCopy;
-    this.writer = model.createDatumWriter(this.writeSchema);
+    this.writer = model.createDatumWriter(writeSchema);
   }
 
   @Override
diff --git a/lang/java/avro/src/main/java/org/apache/avro/reflect/ArrayAccessor.java b/lang/java/avro/src/main/java/org/apache/avro/reflect/ArrayAccessor.java
index 43201d1..fcadd28 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/reflect/ArrayAccessor.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/reflect/ArrayAccessor.java
@@ -32,9 +32,9 @@ class ArrayAccessor {
   static void writeArray(boolean[] data, Encoder out) throws IOException {
     int size = data.length;
     out.setItemCount(size);
-    for (int i = 0; i < size; i++) {
+    for (boolean datum : data) {
       out.startItem();
-      out.writeBoolean(data[i]);
+      out.writeBoolean(datum);
     }
   }
 
@@ -43,54 +43,54 @@ class ArrayAccessor {
   static void writeArray(short[] data, Encoder out) throws IOException {
     int size = data.length;
     out.setItemCount(size);
-    for (int i = 0; i < size; i++) {
+    for (short datum : data) {
       out.startItem();
-      out.writeInt(data[i]);
+      out.writeInt(datum);
     }
   }
 
   static void writeArray(char[] data, Encoder out) throws IOException {
     int size = data.length;
     out.setItemCount(size);
-    for (int i = 0; i < size; i++) {
+    for (char datum : data) {
       out.startItem();
-      out.writeInt(data[i]);
+      out.writeInt(datum);
     }
   }
 
   static void writeArray(int[] data, Encoder out) throws IOException {
     int size = data.length;
     out.setItemCount(size);
-    for (int i = 0; i < size; i++) {
+    for (int datum : data) {
       out.startItem();
-      out.writeInt(data[i]);
+      out.writeInt(datum);
     }
   }
 
   static void writeArray(long[] data, Encoder out) throws IOException {
     int size = data.length;
     out.setItemCount(size);
-    for (int i = 0; i < size; i++) {
+    for (long datum : data) {
       out.startItem();
-      out.writeLong(data[i]);
+      out.writeLong(datum);
     }
   }
 
   static void writeArray(float[] data, Encoder out) throws IOException {
     int size = data.length;
     out.setItemCount(size);
-    for (int i = 0; i < size; i++) {
+    for (float datum : data) {
       out.startItem();
-      out.writeFloat(data[i]);
+      out.writeFloat(datum);
     }
   }
 
   static void writeArray(double[] data, Encoder out) throws IOException {
     int size = data.length;
     out.setItemCount(size);
-    for (int i = 0; i < size; i++) {
+    for (double datum : data) {
       out.startItem();
-      out.writeDouble(data[i]);
+      out.writeDouble(datum);
     }
   }
 
diff --git a/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java b/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
index 5c7728c..d3768f6 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
@@ -137,9 +137,7 @@ public class ReflectData extends SpecificData {
     }
     try {
       getAccessorForField(record, name, pos, state).set(record, o);
-    } catch (IllegalAccessException e) {
-      throw new AvroRuntimeException(e);
-    } catch (IOException e) {
+    } catch (IllegalAccessException | IOException e) {
       throw new AvroRuntimeException(e);
     }
   }
@@ -379,9 +377,7 @@ public class ReflectData extends SpecificData {
       Map m = (Map)datum;
       if (m.size() > 0) {
         Class keyClass = m.keySet().iterator().next().getClass();
-        if (isStringable(keyClass) || isStringType(keyClass))
-          return false;
-        return true;
+        return !isStringable(keyClass) && !isStringType(keyClass);
       }
     }
     return false;
@@ -484,8 +480,7 @@ public class ReflectData extends SpecificData {
   static boolean isNonStringMapSchema(Schema s) {
     if (s != null && s.getType() == Schema.Type.ARRAY) {
       Class c = getClassProp(s, CLASS_PROP);
-      if (c != null && Map.class.isAssignableFrom (c))
-        return true;
+      return c != null && Map.class.isAssignableFrom(c);
     }
     return false;
   }
@@ -586,8 +581,7 @@ public class ReflectData extends SpecificData {
         } else if (c.isEnum()) {                             // Enum
           List<String> symbols = new ArrayList<>();
           Enum[] constants = (Enum[])c.getEnumConstants();
-          for (int i = 0; i < constants.length; i++)
-            symbols.add(constants[i].name());
+          for (Enum constant : constants) symbols.add(constant.name());
           schema = Schema.createEnum(name, doc, space, symbols);
           consumeAvroAliasAnnotation(c, schema);
         } else if (GenericFixed.class.isAssignableFrom(c)) { // fixed
diff --git a/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectDatumWriter.java b/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectDatumWriter.java
index dd24ab3..2d730d2 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectDatumWriter.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectDatumWriter.java
@@ -116,8 +116,8 @@ public class ReflectDatumWriter<T> extends SpecificDatumWriter<T> {
   private void writeObjectArray(Schema element, Object[] data, Encoder out) throws IOException {
     int size = data.length;
     out.setItemCount(size);
-    for (int i = 0; i < size; i++) {
-      this.write(element, data[i], out);
+    for (Object datum : data) {
+      this.write(element, datum, out);
     }
   }
 
diff --git a/lang/java/avro/src/main/java/org/apache/avro/util/Utf8.java b/lang/java/avro/src/main/java/org/apache/avro/util/Utf8.java
index 5f899a4..c66077c 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/util/Utf8.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/util/Utf8.java
@@ -157,7 +157,7 @@ public class Utf8 implements Comparable<Utf8>, CharSequence {
   }
 
   /** Gets the UTF-8 bytes for a String */
-  public static final byte[] getBytesFor(String str) {
+  public static byte[] getBytesFor(String str) {
     return str.getBytes(StandardCharsets.UTF_8);
   }
 
diff --git a/lang/java/avro/src/main/java/org/apache/avro/util/WeakIdentityHashMap.java b/lang/java/avro/src/main/java/org/apache/avro/util/WeakIdentityHashMap.java
index 8e121e4..24be1d9 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/util/WeakIdentityHashMap.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/util/WeakIdentityHashMap.java
@@ -191,10 +191,7 @@ public class WeakIdentityHashMap<K, V> implements Map<K, V> {
         return false;
       }
       IdentityWeakReference ref = (IdentityWeakReference)o;
-      if (this.get() == ref.get()) {
-        return true;
-      }
-      return false;
+      return this.get() == ref.get();
     }
   }
 }
diff --git a/lang/java/avro/src/test/java/org/apache/avro/ByteBufferRecord.java b/lang/java/avro/src/test/java/org/apache/avro/ByteBufferRecord.java
index 2ef7b10..6f9421a 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/ByteBufferRecord.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/ByteBufferRecord.java
@@ -51,8 +51,7 @@ public class ByteBufferRecord {
     if (this.getPayload() == null) return that.getPayload() == null;
     if (!this.getPayload().equals(that.getPayload())) return false;
     if (this.getTp() == null) return that.getTp() == null;
-    if (!this.getTp().equals(that.getTp())) return false;
-    return true;
+    return this.getTp().equals(that.getTp());
   }
 
   @Override
diff --git a/lang/java/avro/src/test/java/org/apache/avro/FooBarSpecificRecord.java b/lang/java/avro/src/test/java/org/apache/avro/FooBarSpecificRecord.java
index 83280c2..673db40 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/FooBarSpecificRecord.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/FooBarSpecificRecord.java
@@ -35,10 +35,10 @@ public class FooBarSpecificRecord extends org.apache.avro.specific.SpecificRecor
   private static SpecificData MODEL$ = new SpecificData();
 
   private static final BinaryMessageEncoder<FooBarSpecificRecord> ENCODER =
-      new BinaryMessageEncoder<FooBarSpecificRecord>(MODEL$, SCHEMA$);
+    new BinaryMessageEncoder<>(MODEL$, SCHEMA$);
 
   private static final BinaryMessageDecoder<FooBarSpecificRecord> DECODER =
-      new BinaryMessageDecoder<FooBarSpecificRecord>(MODEL$, SCHEMA$);
+    new BinaryMessageDecoder<>(MODEL$, SCHEMA$);
 
   /**
    * Return the BinaryMessageDecoder instance used by this class.
@@ -54,7 +54,7 @@ public class FooBarSpecificRecord extends org.apache.avro.specific.SpecificRecor
    * @return a BinaryMessageDecoder instance for this class backed by the given SchemaStore
    */
   public static BinaryMessageDecoder<FooBarSpecificRecord> createDecoder(SchemaStore resolver) {
-    return new BinaryMessageDecoder<FooBarSpecificRecord>(MODEL$, SCHEMA$, resolver);
+    return new BinaryMessageDecoder<>(MODEL$, SCHEMA$, resolver);
   }
 
   /**
diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestCircularReferences.java b/lang/java/avro/src/test/java/org/apache/avro/TestCircularReferences.java
index 7acec08..6838bc3 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/TestCircularReferences.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/TestCircularReferences.java
@@ -127,18 +127,8 @@ public class TestCircularReferences {
 
   @BeforeClass
   public static void addReferenceTypes() {
-    LogicalTypes.register(Referenceable.REFERENCEABLE, new LogicalTypes.LogicalTypeFactory() {
-      @Override
-      public LogicalType fromSchema(Schema schema) {
-        return new Referenceable(schema);
-      }
-    });
-    LogicalTypes.register(Reference.REFERENCE, new LogicalTypes.LogicalTypeFactory() {
-      @Override
-      public LogicalType fromSchema(Schema schema) {
-        return new Reference(schema);
-      }
-    });
+    LogicalTypes.register(Referenceable.REFERENCEABLE, Referenceable::new);
+    LogicalTypes.register(Reference.REFERENCE, Reference::new);
   }
 
   public static class ReferenceManager {
@@ -231,18 +221,9 @@ public class TestCircularReferences {
             record.put(refField.pos(), references.get(id));
 
           } else {
-            List<Callback> callbacks = callbacksById.get(id);
-            if (callbacks == null) {
-              callbacks = new ArrayList<>();
-              callbacksById.put(id, callbacks);
-            }
+            List<Callback> callbacks = callbacksById.computeIfAbsent(id, k -> new ArrayList<>());
             // add a callback to resolve this reference when the id is available
-            callbacks.add(new Callback() {
-              @Override
-              public void set(Object referenceable) {
-                record.put(refField.pos(), referenceable);
-              }
-            });
+            callbacks.add(referenceable -> record.put(refField.pos(), referenceable));
           }
         }
 
@@ -365,17 +346,11 @@ public class TestCircularReferences {
   private <D> List<D> read(GenericData model, Schema schema, File file) throws IOException {
     DatumReader<D> reader = newReader(model, schema);
     List<D> data = new ArrayList<>();
-    FileReader<D> fileReader = null;
 
-    try {
-      fileReader = new DataFileReader<>(file, reader);
+    try (FileReader<D> fileReader = new DataFileReader<>(file, reader)) {
       for (D datum : fileReader) {
         data.add(datum);
       }
-    } finally {
-      if (fileReader != null) {
-        fileReader.close();
-      }
     }
 
     return data;
@@ -390,15 +365,12 @@ public class TestCircularReferences {
   private <D> File write(GenericData model, Schema schema, D... data) throws IOException {
     File file = temp.newFile();
     DatumWriter<D> writer = model.createDatumWriter(schema);
-    DataFileWriter<D> fileWriter = new DataFileWriter<>(writer);
 
-    try {
+    try (DataFileWriter<D> fileWriter = new DataFileWriter<>(writer)) {
       fileWriter.create(schema, file);
       for (D datum : data) {
         fileWriter.append(datum);
       }
-    } finally {
-      fileWriter.close();
     }
 
     return file;
diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestDataFile.java b/lang/java/avro/src/test/java/org/apache/avro/TestDataFile.java
index de74ce9..28ef750 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/TestDataFile.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/TestDataFile.java
@@ -148,9 +148,7 @@ public class TestDataFile {
   }
 
   private void testGenericRead() throws IOException {
-    DataFileReader<Object> reader =
-      new DataFileReader<>(makeFile(), new GenericDatumReader<>());
-    try {
+    try (DataFileReader<Object> reader = new DataFileReader<>(makeFile(), new GenericDatumReader<>())) {
       Object datum = null;
       if (VALIDATE) {
         for (Object expected : new RandomData(SCHEMA, COUNT, SEED)) {
@@ -162,43 +160,35 @@ public class TestDataFile {
           datum = reader.next(datum);
         }
       }
-    } finally {
-      reader.close();
     }
   }
 
   private void testSplits() throws IOException {
     File file = makeFile();
-    DataFileReader<Object> reader =
-      new DataFileReader<>(file, new GenericDatumReader<>());
-    Random rand = new Random(SEED);
-    try {
+    try (DataFileReader<Object> reader = new DataFileReader<>(file, new GenericDatumReader<>())) {
+      Random rand = new Random(SEED);
       int splits = 10;                            // number of splits
-      int length = (int)file.length();            // length of file
+      int length = (int) file.length();            // length of file
       int end = length;                           // end of split
       int remaining = end;                        // bytes remaining
       int count = 0;                              // count of entries
       while (remaining > 0) {
-        int start = Math.max(0, end - rand.nextInt(2*length/splits));
+        int start = Math.max(0, end - rand.nextInt(2 * length / splits));
         reader.sync(start);                       // count entries in split
         while (!reader.pastSync(end)) {
           reader.next();
           count++;
         }
-        remaining -= end-start;
+        remaining -= end - start;
         end = start;
       }
       assertEquals(COUNT, count);
-    } finally {
-      reader.close();
     }
   }
 
   private void testSyncDiscovery() throws IOException {
     File file = makeFile();
-    DataFileReader<Object> reader =
-      new DataFileReader<>(file, new GenericDatumReader<>());
-    try {
+    try (DataFileReader<Object> reader = new DataFileReader<>(file, new GenericDatumReader<>())) {
       // discover the sync points
       ArrayList<Long> syncs = new ArrayList<>();
       long previousSync = -1;
@@ -211,37 +201,29 @@ public class TestDataFile {
       }
       // confirm that the first point is the one reached by sync(0)
       reader.sync(0);
-      assertEquals(reader.previousSync(), (long)syncs.get(0));
+      assertEquals(reader.previousSync(), (long) syncs.get(0));
       // and confirm that all points are reachable
       for (Long sync : syncs) {
         reader.seek(sync);
         assertNotNull(reader.next());
       }
-    } finally {
-      reader.close();
     }
   }
 
   private void testGenericAppend() throws IOException {
     File file = makeFile();
     long start = file.length();
-    DataFileWriter<Object> writer =
-      new DataFileWriter<>(new GenericDatumWriter<>())
-      .appendTo(file);
-    try {
-      for (Object datum : new RandomData(SCHEMA, COUNT, SEED+1)) {
+    try (DataFileWriter<Object> writer = new DataFileWriter<>(new GenericDatumWriter<>())
+      .appendTo(file)) {
+      for (Object datum : new RandomData(SCHEMA, COUNT, SEED + 1)) {
         writer.append(datum);
       }
-    } finally {
-      writer.close();
     }
-    DataFileReader<Object> reader =
-      new DataFileReader<>(file, new GenericDatumReader<>());
-    try {
+    try (DataFileReader<Object> reader = new DataFileReader<>(file, new GenericDatumReader<>())) {
       reader.seek(start);
       Object datum = null;
       if (VALIDATE) {
-        for (Object expected : new RandomData(SCHEMA, COUNT, SEED+1)) {
+        for (Object expected : new RandomData(SCHEMA, COUNT, SEED + 1)) {
           datum = reader.next(datum);
           assertEquals(expected, datum);
         }
@@ -250,8 +232,6 @@ public class TestDataFile {
           datum = reader.next(datum);
         }
       }
-    } finally {
-      reader.close();
     }
   }
 
@@ -323,18 +303,13 @@ public class TestDataFile {
   }
 
   private void testFSync(boolean useFile) throws IOException {
-    DataFileWriter<Object> writer =
-      new DataFileWriter<>(new GenericDatumWriter<>());
-    try {
+    try (DataFileWriter<Object> writer = new DataFileWriter<>(new GenericDatumWriter<>())) {
       writer.setFlushOnEveryBlock(false);
       TestingByteArrayOutputStream out = new TestingByteArrayOutputStream();
       if (useFile) {
         File f = makeFile();
-        SeekableFileInput in = new SeekableFileInput(f);
-        try {
+        try (SeekableFileInput in = new SeekableFileInput(f)) {
           writer.appendTo(in, out);
-        } finally {
-          in.close();
         }
       } else {
         writer.create(SCHEMA, out);
@@ -351,8 +326,6 @@ public class TestDataFile {
       }
       System.out.println("Total number of syncs: " + out.syncCount);
       assertEquals(syncCounter, out.syncCount);
-    } finally {
-      writer.close();
     }
   }
 
diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestDataFileReflect.java b/lang/java/avro/src/test/java/org/apache/avro/TestDataFileReflect.java
index 91236a4..663d7d8 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/TestDataFileReflect.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/TestDataFileReflect.java
@@ -131,7 +131,7 @@ public class TestDataFileReflect {
     bbr.setTp(TypeEnum.b);
 
     ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
-    ReflectDatumWriter<ByteBufferRecord> writer = new ReflectDatumWriter<ByteBufferRecord>(ByteBufferRecord.class);
+    ReflectDatumWriter<ByteBufferRecord> writer = new ReflectDatumWriter<>(ByteBufferRecord.class);
     BinaryEncoder avroEncoder = EncoderFactory.get().blockingBinaryEncoder(outputStream, null);
     writer.write(bbr, avroEncoder);
     avroEncoder.flush();
@@ -139,7 +139,7 @@ public class TestDataFileReflect {
     byte[] bytes = outputStream.toByteArray();
 
     ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
-    ReflectDatumReader<ByteBufferRecord> datumReader = new ReflectDatumReader<ByteBufferRecord>(ByteBufferRecord.class);
+    ReflectDatumReader<ByteBufferRecord> datumReader = new ReflectDatumReader<>(ByteBufferRecord.class);
     BinaryDecoder avroDecoder = DecoderFactory.get().binaryDecoder(inputStream, null);
     ByteBufferRecord deserialized = datumReader.read(null, avroDecoder);
 
@@ -156,7 +156,7 @@ public class TestDataFileReflect {
     CheckList<BazRecord> check = new CheckList<>();
     try(FileOutputStream fos = new FileOutputStream(file)) {
       Schema schema = ReflectData.get().getSchema(BazRecord.class);
-      try (DataFileWriter<BazRecord> writer = new DataFileWriter<>(new ReflectDatumWriter<BazRecord>(schema))) {
+      try (DataFileWriter<BazRecord> writer = new DataFileWriter<>(new ReflectDatumWriter<>(schema))) {
         writer.create(schema, fos);
 
         // test writing to a file
diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestLogicalType.java b/lang/java/avro/src/test/java/org/apache/avro/TestLogicalType.java
index ec143b9..caa68b7 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/TestLogicalType.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/TestLogicalType.java
@@ -73,12 +73,9 @@ public class TestLogicalType {
     for (final Schema schema : nonBytes) {
       assertThrows("Should reject type: " + schema.getType(),
           IllegalArgumentException.class,
-          "Logical type decimal must be backed by fixed or bytes", new Callable() {
-            @Override
-            public Object call() throws Exception {
-              decimal.addToSchema(schema);
-              return null;
-            }
+          "Logical type decimal must be backed by fixed or bytes", () -> {
+            decimal.addToSchema(schema);
+            return null;
           });
     }
   }
@@ -107,12 +104,9 @@ public class TestLogicalType {
     // 4 bytes can hold up to 9 digits of precision
     final Schema schema = Schema.createFixed("aDecimal", null, null, 4);
     assertThrows("Should reject precision", IllegalArgumentException.class,
-        "fixed(4) cannot store 10 digits (max 9)", new Callable() {
-          @Override
-          public Object call() throws Exception {
-            LogicalTypes.decimal(10).addToSchema(schema);
-            return null;
-          }
+        "fixed(4) cannot store 10 digits (max 9)", () -> {
+          LogicalTypes.decimal(10).addToSchema(schema);
+          return null;
         }
     );
     Assert.assertNull("Invalid logical type should not be set on schema",
@@ -123,12 +117,9 @@ public class TestLogicalType {
   public void testDecimalFailsWithZeroPrecision() {
     final Schema schema = Schema.createFixed("aDecimal", null, null, 4);
     assertThrows("Should reject precision", IllegalArgumentException.class,
-        "Invalid decimal precision: 0 (must be positive)", new Callable() {
-          @Override
-          public Object call() throws Exception {
-            LogicalTypes.decimal(0).addToSchema(schema);
-            return null;
-          }
+        "Invalid decimal precision: 0 (must be positive)", () -> {
+          LogicalTypes.decimal(0).addToSchema(schema);
+          return null;
         });
     Assert.assertNull("Invalid logical type should not be set on schema",
         LogicalTypes.fromSchemaIgnoreInvalid(schema));
@@ -138,12 +129,9 @@ public class TestLogicalType {
   public void testDecimalFailsWithNegativePrecision() {
     final Schema schema = Schema.createFixed("aDecimal", null, null, 4);
     assertThrows("Should reject precision", IllegalArgumentException.class,
-        "Invalid decimal precision: -9 (must be positive)", new Callable() {
-          @Override
-          public Object call() throws Exception {
-            LogicalTypes.decimal(-9).addToSchema(schema);
-            return null;
-          }
+        "Invalid decimal precision: -9 (must be positive)", () -> {
+          LogicalTypes.decimal(-9).addToSchema(schema);
+          return null;
         });
     Assert.assertNull("Invalid logical type should not be set on schema",
         LogicalTypes.fromSchemaIgnoreInvalid(schema));
@@ -154,13 +142,10 @@ public class TestLogicalType {
     final Schema schema = Schema.createFixed("aDecimal", null, null, 4);
     assertThrows("Should reject precision", IllegalArgumentException.class,
         "Invalid decimal scale: 10 (greater than precision: 9)",
-        new Callable() {
-          @Override
-          public Object call() throws Exception {
-            LogicalTypes.decimal(9, 10).addToSchema(schema);
-            return null;
-          }
-        });
+      () -> {
+        LogicalTypes.decimal(9, 10).addToSchema(schema);
+        return null;
+      });
     Assert.assertNull("Invalid logical type should not be set on schema",
         LogicalTypes.fromSchemaIgnoreInvalid(schema));
   }
@@ -169,12 +154,9 @@ public class TestLogicalType {
   public void testDecimalFailsWithNegativeScale() {
     final Schema schema = Schema.createFixed("aDecimal", null, null, 4);
     assertThrows("Should reject precision", IllegalArgumentException.class,
-        "Invalid decimal scale: -2 (must be positive)", new Callable() {
-          @Override
-          public Object call() throws Exception {
-            LogicalTypes.decimal(9, -2).addToSchema(schema);
-            return null;
-          }
+        "Invalid decimal scale: -2 (must be positive)", () -> {
+          LogicalTypes.decimal(9, -2).addToSchema(schema);
+          return null;
         });
     Assert.assertNull("Invalid logical type should not be set on schema",
         LogicalTypes.fromSchemaIgnoreInvalid(schema));
@@ -186,12 +168,9 @@ public class TestLogicalType {
     LogicalTypes.decimal(9).addToSchema(schema);
     assertThrows("Should reject second logical type",
         AvroRuntimeException.class,
-        "Can't overwrite property: scale", new Callable() {
-          @Override
-          public Object call() throws Exception {
-            LogicalTypes.decimal(9, 2).addToSchema(schema);
-            return null;
-          }
+        "Can't overwrite property: scale", () -> {
+          LogicalTypes.decimal(9, 2).addToSchema(schema);
+          return null;
         }
     );
     Assert.assertEquals("First logical type should still be set on schema",
diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestNestedRecords.java b/lang/java/avro/src/test/java/org/apache/avro/TestNestedRecords.java
index 5b1afdf..17ee571 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/TestNestedRecords.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/TestNestedRecords.java
@@ -67,7 +67,7 @@ public class TestNestedRecords {
     final ByteArrayInputStream inputStream = new ByteArrayInputStream(inputAsExpected.getBytes(UTF_8));
 
     final JsonDecoder decoder = DecoderFactory.get().jsonDecoder(parent, inputStream);
-    final DatumReader<Object> reader = new GenericDatumReader<Object>(parent);
+    final DatumReader<Object> reader = new GenericDatumReader<>(parent);
 
     final GenericData.Record  decoded = (GenericData.Record) reader.read(null, decoder);
 
@@ -113,7 +113,7 @@ public class TestNestedRecords {
     final ByteArrayInputStream inputStream = new ByteArrayInputStream(inputAsExpected.getBytes());
 
     final JsonDecoder decoder = DecoderFactory.get().jsonDecoder(parent, inputStream);
-    final DatumReader<Object> reader = new GenericDatumReader<Object>(parent);
+    final DatumReader<Object> reader = new GenericDatumReader<>(parent);
 
     final GenericData.Record decoded = (GenericData.Record) reader.read(null, decoder);
 
diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaBuilder.java b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaBuilder.java
index 7046fb3..63d502b 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaBuilder.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaBuilder.java
@@ -164,7 +164,7 @@ public class TestSchemaBuilder {
 
   @Test
   public void testArrayObjectProp() {
-    List<Object> values = new ArrayList<Object>();
+    List<Object> values = new ArrayList<>();
     values.add(true);
     values.add(Integer.MAX_VALUE);
     values.add(Long.MAX_VALUE);
@@ -198,7 +198,7 @@ public class TestSchemaBuilder {
 
   @Test
   public void testFieldArrayObjectProp() {
-    List<Object> values = new ArrayList<Object>();
+    List<Object> values = new ArrayList<>();
     values.add(true);
     values.add(Integer.MAX_VALUE);
     values.add(Long.MAX_VALUE);
@@ -237,7 +237,7 @@ public class TestSchemaBuilder {
 
   @Test
   public void testMapObjectProp() {
-    Map<String, Object> values = new HashMap<String, Object>();
+    Map<String, Object> values = new HashMap<>();
     values.put("booleanKey", true);
     values.put("intKey", Integer.MAX_VALUE);
     values.put("longKey", Long.MAX_VALUE);
@@ -277,7 +277,7 @@ public class TestSchemaBuilder {
 
   @Test
   public void testFieldMapObjectProp() {
-    Map<String, Object> values = new HashMap<String, Object>();
+    Map<String, Object> values = new HashMap<>();
     values.put("booleanKey", true);
     values.put("intKey", Integer.MAX_VALUE);
     values.put("longKey", Long.MAX_VALUE);
diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibility.java b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibility.java
index 0f7e909..3655290 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibility.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibility.java
@@ -152,7 +152,7 @@ public class TestSchemaCompatibility {
             invalidReader,
             STRING_ARRAY_SCHEMA,
             "reader type: MAP not compatible with writer type: ARRAY",
-            asList("")),
+              Collections.singletonList("")),
             invalidReader,
             STRING_ARRAY_SCHEMA,
             String.format(
@@ -185,7 +185,7 @@ public class TestSchemaCompatibility {
             INT_SCHEMA,
             STRING_SCHEMA,
             "reader type: INT not compatible with writer type: STRING",
-            asList("")),
+              Collections.singletonList("")),
             INT_SCHEMA,
             STRING_SCHEMA,
             String.format(
@@ -330,9 +330,9 @@ public class TestSchemaCompatibility {
     validateIncompatibleSchemas(
         reader,
         writer,
-        asList(incompatibility),
-        asList(message),
-        asList(location)
+      Collections.singletonList(incompatibility),
+      Collections.singletonList(message),
+      Collections.singletonList(location)
     );
   }
 
@@ -489,7 +489,7 @@ public class TestSchemaCompatibility {
 
       LOG.debug(
           "Decode datum {} whose writer is {} with reader {}.",
-          new Object[]{datum, writerSchema, readerSchema});
+        datum, writerSchema, readerSchema);
       final byte[] bytes = baos.toByteArray();
       final Decoder decoder = DecoderFactory.get().resolvingDecoder(
           writerSchema, readerSchema,
diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityFixedSizeMismatch.java b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityFixedSizeMismatch.java
index e233ad2..8502f4e 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityFixedSizeMismatch.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityFixedSizeMismatch.java
@@ -20,10 +20,7 @@ package org.apache.avro;
 import static org.apache.avro.TestSchemaCompatibility.validateIncompatibleSchemas;
 import static org.apache.avro.TestSchemas.*;
 
-import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
 
 import org.apache.avro.SchemaCompatibility.SchemaIncompatibilityType;
 import org.junit.Test;
diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityMissingEnumSymbols.java b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityMissingEnumSymbols.java
index e1eaeb9..9841c64 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityMissingEnumSymbols.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityMissingEnumSymbols.java
@@ -20,10 +20,7 @@ package org.apache.avro;
 import static org.apache.avro.TestSchemaCompatibility.validateIncompatibleSchemas;
 import static org.apache.avro.TestSchemas.*;
 
-import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
 
 import org.apache.avro.SchemaCompatibility.SchemaIncompatibilityType;
 import org.junit.Test;
diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityMissingUnionBranch.java b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityMissingUnionBranch.java
index 1607bd3..42d7236 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityMissingUnionBranch.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityMissingUnionBranch.java
@@ -21,7 +21,6 @@ import static java.util.Arrays.asList;
 import static org.apache.avro.TestSchemaCompatibility.validateIncompatibleSchemas;
 import static org.apache.avro.TestSchemas.*;
 
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
@@ -61,27 +60,27 @@ public class TestSchemaCompatibilityMissingUnionBranch {
   @Parameters(name = "r: {0} | w: {1}")
   public static Iterable<Object[]> data() {
     Object[][] fields = { //
-        { INT_UNION_SCHEMA, INT_STRING_UNION_SCHEMA, asList("reader union lacking writer type: STRING"), asList("/1") },
-        { STRING_UNION_SCHEMA, INT_STRING_UNION_SCHEMA, asList("reader union lacking writer type: INT"), asList("/0") },
-        { INT_UNION_SCHEMA, UNION_INT_RECORD1, asList("reader union lacking writer type: RECORD"), asList("/1") },
-        { INT_UNION_SCHEMA, UNION_INT_RECORD2, asList("reader union lacking writer type: RECORD"), asList("/1") },
+        { INT_UNION_SCHEMA, INT_STRING_UNION_SCHEMA, Collections.singletonList("reader union lacking writer type: STRING"), Collections.singletonList("/1")},
+        { STRING_UNION_SCHEMA, INT_STRING_UNION_SCHEMA, Collections.singletonList("reader union lacking writer type: INT"), Collections.singletonList("/0")},
+        { INT_UNION_SCHEMA, UNION_INT_RECORD1, Collections.singletonList("reader union lacking writer type: RECORD"), Collections.singletonList("/1")},
+        { INT_UNION_SCHEMA, UNION_INT_RECORD2, Collections.singletonList("reader union lacking writer type: RECORD"), Collections.singletonList("/1")},
         // more info in the subset schemas
-        { UNION_INT_RECORD1, UNION_INT_RECORD2, asList("reader union lacking writer type: RECORD"), asList("/1") },
-        { INT_UNION_SCHEMA, UNION_INT_ENUM1_AB, asList("reader union lacking writer type: ENUM"), asList("/1") },
-        { INT_UNION_SCHEMA, UNION_INT_FIXED_4_BYTES, asList("reader union lacking writer type: FIXED"), asList("/1") },
-        { INT_UNION_SCHEMA, UNION_INT_BOOLEAN, asList("reader union lacking writer type: BOOLEAN"), asList("/1") },
-        { INT_UNION_SCHEMA, LONG_UNION_SCHEMA, asList("reader union lacking writer type: LONG"), asList("/0") },
-        { INT_UNION_SCHEMA, FLOAT_UNION_SCHEMA, asList("reader union lacking writer type: FLOAT"), asList("/0") },
-        { INT_UNION_SCHEMA, DOUBLE_UNION_SCHEMA, asList("reader union lacking writer type: DOUBLE"), asList("/0") },
-        { INT_UNION_SCHEMA, BYTES_UNION_SCHEMA, asList("reader union lacking writer type: BYTES"), asList("/0") },
-        { INT_UNION_SCHEMA, UNION_INT_ARRAY_INT, asList("reader union lacking writer type: ARRAY"), asList("/1") },
-        { INT_UNION_SCHEMA, UNION_INT_MAP_INT, asList("reader union lacking writer type: MAP"), asList("/1") },
-        { INT_UNION_SCHEMA, UNION_INT_NULL, asList("reader union lacking writer type: NULL"), asList("/1") },
+        { UNION_INT_RECORD1, UNION_INT_RECORD2, Collections.singletonList("reader union lacking writer type: RECORD"), Collections.singletonList("/1")},
+        { INT_UNION_SCHEMA, UNION_INT_ENUM1_AB, Collections.singletonList("reader union lacking writer type: ENUM"), Collections.singletonList("/1")},
+        { INT_UNION_SCHEMA, UNION_INT_FIXED_4_BYTES, Collections.singletonList("reader union lacking writer type: FIXED"), Collections.singletonList("/1")},
+        { INT_UNION_SCHEMA, UNION_INT_BOOLEAN, Collections.singletonList("reader union lacking writer type: BOOLEAN"), Collections.singletonList("/1")},
+        { INT_UNION_SCHEMA, LONG_UNION_SCHEMA, Collections.singletonList("reader union lacking writer type: LONG"), Collections.singletonList("/0")},
+        { INT_UNION_SCHEMA, FLOAT_UNION_SCHEMA, Collections.singletonList("reader union lacking writer type: FLOAT"), Collections.singletonList("/0")},
+        { INT_UNION_SCHEMA, DOUBLE_UNION_SCHEMA, Collections.singletonList("reader union lacking writer type: DOUBLE"), Collections.singletonList("/0")},
+        { INT_UNION_SCHEMA, BYTES_UNION_SCHEMA, Collections.singletonList("reader union lacking writer type: BYTES"), Collections.singletonList("/0")},
+        { INT_UNION_SCHEMA, UNION_INT_ARRAY_INT, Collections.singletonList("reader union lacking writer type: ARRAY"), Collections.singletonList("/1")},
+        { INT_UNION_SCHEMA, UNION_INT_MAP_INT, Collections.singletonList("reader union lacking writer type: MAP"), Collections.singletonList("/1")},
+        { INT_UNION_SCHEMA, UNION_INT_NULL, Collections.singletonList("reader union lacking writer type: NULL"), Collections.singletonList("/1")},
         { INT_UNION_SCHEMA, INT_LONG_FLOAT_DOUBLE_UNION_SCHEMA,
               asList("reader union lacking writer type: LONG", "reader union lacking writer type: FLOAT", "reader union lacking writer type: DOUBLE"),
               asList("/1", "/2", "/3") },
         { A_DINT_B_DINT_UNION_RECORD1, A_DINT_B_DINT_STRING_UNION_RECORD1,
-              asList("reader union lacking writer type: STRING"), asList("/fields/1/type/1") } };
+          Collections.singletonList("reader union lacking writer type: STRING"), Collections.singletonList("/fields/1/type/1")} };
     return Arrays.asList(fields);
   }
 
diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityNameMismatch.java b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityNameMismatch.java
index 66f486b..104eed6 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityNameMismatch.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityNameMismatch.java
@@ -20,9 +20,7 @@ package org.apache.avro;
 import static org.apache.avro.TestSchemaCompatibility.validateIncompatibleSchemas;
 import static org.apache.avro.TestSchemas.*;
 
-import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.List;
 
 import org.apache.avro.SchemaCompatibility.SchemaIncompatibilityType;
 import org.junit.Test;
diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityReaderFieldMissingDefaultValue.java b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityReaderFieldMissingDefaultValue.java
index 3256a88..60d0b56 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityReaderFieldMissingDefaultValue.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityReaderFieldMissingDefaultValue.java
@@ -20,9 +20,7 @@ package org.apache.avro;
 import static org.apache.avro.TestSchemaCompatibility.validateIncompatibleSchemas;
 import static org.apache.avro.TestSchemas.*;
 
-import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.List;
 
 import org.apache.avro.SchemaCompatibility.SchemaIncompatibilityType;
 import org.junit.Test;
diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityTypeMismatch.java b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityTypeMismatch.java
index 187f8c2..98171e3 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityTypeMismatch.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibilityTypeMismatch.java
@@ -20,9 +20,7 @@ package org.apache.avro;
 import static org.apache.avro.TestSchemaCompatibility.validateIncompatibleSchemas;
 import static org.apache.avro.TestSchemas.*;
 
-import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.List;
 
 import org.apache.avro.SchemaCompatibility.SchemaIncompatibilityType;
 import org.junit.Test;
diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaNormalization.java b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaNormalization.java
index 06ba722..0a1382d 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaNormalization.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaNormalization.java
@@ -22,9 +22,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
 import java.io.BufferedReader;
-import java.io.FileReader;
 import java.io.IOException;
-import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.ArrayList;
@@ -118,11 +116,11 @@ public class TestSchemaNormalization {
 
   private static long altExtend(long poly, int degree, long fp, byte[] b) {
     final long overflowBit = 1L<<(64-degree);
-    for (int i = 0; i < b.length; i++) {
-      for (int j = 1; j < 129; j = j<<1) {
+    for (byte b1 : b) {
+      for (int j = 1; j < 129; j = j << 1) {
         boolean overflow = (0 != (fp & overflowBit));
         fp >>>= 1;
-        if (0 != (j&b[i])) fp |= ONE; // shift in the input bit
+        if (0 != (j & b1)) fp |= ONE; // shift in the input bit
         if (overflow) {
           fp ^= poly; // hi-order coeff of poly kills overflow bit
         }
diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaValidation.java b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaValidation.java
index 1ede757..953f97e 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaValidation.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaValidation.java
@@ -20,7 +20,6 @@ package org.apache.avro;
 import static org.apache.avro.TestSchemas.*;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
@@ -310,16 +309,16 @@ public class TestSchemaValidation {
 
   @Test
   public void testUnionWithIncompatibleElements() throws SchemaValidationException {
-    Schema union1 = Schema.createUnion(Arrays.asList(rec));
-    Schema union2 = Schema.createUnion(Arrays.asList(rec4));
+    Schema union1 = Schema.createUnion(Collections.singletonList(rec));
+    Schema union2 = Schema.createUnion(Collections.singletonList(rec4));
     testValidatorFails(builder.canReadStrategy().validateAll(),
         union2, union1);
   }
 
   @Test
   public void testUnionWithCompatibleElements() throws SchemaValidationException {
-    Schema union1 = Schema.createUnion(Arrays.asList(rec));
-    Schema union2 = Schema.createUnion(Arrays.asList(rec3));
+    Schema union1 = Schema.createUnion(Collections.singletonList(rec));
+    Schema union2 = Schema.createUnion(Collections.singletonList(rec3));
     testValidatorPasses(builder.canReadStrategy().validateAll(),
         union2, union1);
   }
@@ -381,6 +380,6 @@ public class TestSchemaValidation {
   public void testRecursiveSchemaValidation() throws SchemaValidationException {
     // before AVRO-2122, this would cause a StackOverflowError
     final SchemaValidator backwardValidator = builder.canReadStrategy().validateLatest();
-    backwardValidator.validate(recursiveSchema, Arrays.asList(recursiveSchema));
+    backwardValidator.validate(recursiveSchema, Collections.singletonList(recursiveSchema));
   }
 }
diff --git a/lang/java/avro/src/test/java/org/apache/avro/data/RecordBuilderBaseTest.java b/lang/java/avro/src/test/java/org/apache/avro/data/RecordBuilderBaseTest.java
index 33654aa..2cae31b 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/data/RecordBuilderBaseTest.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/data/RecordBuilderBaseTest.java
@@ -38,9 +38,7 @@ public class RecordBuilderBaseTest {
   @BeforeClass()
   public static void setUpBeforeClass() {
     primitives = new HashSet<>(Arrays.asList(Type.values()));
-    primitives.removeAll(Arrays.asList(new Type[] {
-        Type.RECORD, Type.ENUM, Type.ARRAY, Type.MAP, Type.UNION, Type.FIXED
-    }));
+    primitives.removeAll(Arrays.asList(Type.RECORD, Type.ENUM, Type.ARRAY, Type.MAP, Type.UNION, Type.FIXED));
 
     nonNullPrimitives = new HashSet<>(primitives);
     nonNullPrimitives.remove(Type.NULL);
@@ -71,9 +69,7 @@ public class RecordBuilderBaseTest {
   @Test
   public void testIsValidValueWithUnion() {
     // Verify that null values are not valid for a union with no null type:
-    Schema unionWithoutNull = Schema.createUnion(Arrays.asList(new Schema[] {
-        Schema.create(Type.STRING), Schema.create(Type.BOOLEAN)
-    }));
+    Schema unionWithoutNull = Schema.createUnion(Arrays.asList(Schema.create(Type.STRING), Schema.create(Type.BOOLEAN)));
 
     Assert.assertTrue(RecordBuilderBase.isValidValue(
         new Field("f", unionWithoutNull, null, null), new Object()));
@@ -81,9 +77,7 @@ public class RecordBuilderBaseTest {
         new Field("f", unionWithoutNull, null, null), null));
 
     // Verify that null values are valid for a union with a null type:
-    Schema unionWithNull = Schema.createUnion(Arrays.asList(new Schema[] {
-        Schema.create(Type.STRING), Schema.create(Type.NULL)
-    }));
+    Schema unionWithNull = Schema.createUnion(Arrays.asList(Schema.create(Type.STRING), Schema.create(Type.NULL)));
 
     Assert.assertTrue(RecordBuilderBase.isValidValue(
         new Field("f", unionWithNull, null, null), new Object()));
diff --git a/lang/java/avro/src/test/java/org/apache/avro/file/TestIOExceptionDuringWrite.java b/lang/java/avro/src/test/java/org/apache/avro/file/TestIOExceptionDuringWrite.java
index 35fdcdf..fae6fa7 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/file/TestIOExceptionDuringWrite.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/file/TestIOExceptionDuringWrite.java
@@ -58,8 +58,7 @@ public class TestIOExceptionDuringWrite {
 
   @Test
   public void testNoWritingAfterException() throws IOException {
-    DataFileWriter<Object> writer = new DataFileWriter<Object>(new GenericDatumWriter<Object>());
-    try {
+    try (DataFileWriter<Object> writer = new DataFileWriter<>(new GenericDatumWriter<>())) {
       writer.create(SCHEMA, new FailingOutputStream(100000));
       int recordCnt = 0;
       for (Object datum : new RandomData(SCHEMA, 100000, 42)) {
@@ -70,8 +69,6 @@ public class TestIOExceptionDuringWrite {
       }
     } catch (IOException e) {
       return;
-    } finally {
-      writer.close();
     }
     fail("IOException should have been thrown");
   }
diff --git a/lang/java/avro/src/test/java/org/apache/avro/file/TestSeekableByteArrayInput.java b/lang/java/avro/src/test/java/org/apache/avro/file/TestSeekableByteArrayInput.java
index 01d6c3d..3a8cb15 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/file/TestSeekableByteArrayInput.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/file/TestSeekableByteArrayInput.java
@@ -38,15 +38,9 @@ public class TestSeekableByteArrayInput {
     private byte[] getSerializedMessage(IndexedRecord message, Schema schema) throws Exception {
         ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
         SpecificDatumWriter<IndexedRecord> writer = new SpecificDatumWriter<>();
-        DataFileWriter<IndexedRecord> dfw = null;
-        try {
-            dfw = new DataFileWriter<>(writer).create(schema, baos);
-            dfw.append(message);
-        } finally {
-            if (dfw != null) {
-                dfw.close();
-            }
-        }
+      try (DataFileWriter<IndexedRecord> dfw = new DataFileWriter<>(writer).create(schema, baos)) {
+        dfw.append(message);
+      }
         return baos.toByteArray();
     }
 
@@ -67,17 +61,10 @@ public class TestSeekableByteArrayInput {
         byte[] data = getSerializedMessage(message, testSchema);
 
         GenericDatumReader<IndexedRecord> reader = new GenericDatumReader<>(testSchema);
-
-        SeekableInput in = new SeekableByteArrayInput(data);
-        FileReader<IndexedRecord> dfr = null;
-        IndexedRecord result = null;
-        try {
-            dfr = DataFileReader.openReader(in, reader);
-            result = dfr.next();
-        } finally {
-            if (dfr != null) {
-                dfr.close();
-            }
+        final IndexedRecord result;
+        try (SeekableInput in = new SeekableByteArrayInput(data);
+             FileReader<IndexedRecord> dfr = DataFileReader.openReader(in, reader)) {
+          result = dfr.next();
         }
         Assert.assertNotNull(result);
         Assert.assertTrue(result instanceof GenericRecord);
diff --git a/lang/java/avro/src/test/java/org/apache/avro/file/codec/CustomCodec.java b/lang/java/avro/src/test/java/org/apache/avro/file/codec/CustomCodec.java
index dd52e4e..c022a5e 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/file/codec/CustomCodec.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/file/codec/CustomCodec.java
@@ -81,12 +81,8 @@ public class CustomCodec extends Codec {
     original.rewind();
     ByteBuffer compressedB = other.compress(original);
 
-    if (this.decompress(compressedA).equals(other.decompress((ByteBuffer) compressedA.rewind())) &&
-      this.decompress(compressedB).equals(other.decompress((ByteBuffer) compressedB.rewind()))
-      ) {
-      return true;
-    }
-    return false;
+    return this.decompress(compressedA).equals(other.decompress((ByteBuffer) compressedA.rewind())) &&
+      this.decompress(compressedB).equals(other.decompress((ByteBuffer) compressedB.rewind()));
   }
 
   @Override
diff --git a/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericData.java b/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericData.java
index c90e1da..ea6c484 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericData.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericData.java
@@ -459,7 +459,7 @@ public class TestGenericData {
     Schema schema = Schema.createRecord("my_record", "doc", "mytest", false);
     Field byte_field =
       new Field("bytes", Schema.create(Type.BYTES), null, null);
-    schema.setFields(Arrays.asList(byte_field));
+    schema.setFields(Collections.singletonList(byte_field));
 
     GenericRecord record = new GenericData.Record(schema);
     record.put(byte_field.name(), buffer);
@@ -551,48 +551,48 @@ public class TestGenericData {
   @Test
   public void testToStringSameValues() throws IOException {
     List<Field> fields = new ArrayList<>();
-    fields.add(new Field("nullstring1", Schema.create(Type.STRING), null, (Object)null));
-    fields.add(new Field("nullstring2", Schema.create(Type.STRING), null, (Object)null));
+    fields.add(new Field("nullstring1", Schema.create(Type.STRING), null, null));
+    fields.add(new Field("nullstring2", Schema.create(Type.STRING), null, null));
 
-    fields.add(new Field("string1", Schema.create(Type.STRING  ), null, (Object)null));
-    fields.add(new Field("string2", Schema.create(Type.STRING  ), null, (Object)null));
+    fields.add(new Field("string1", Schema.create(Type.STRING  ), null, null));
+    fields.add(new Field("string2", Schema.create(Type.STRING  ), null, null));
 
-    fields.add(new Field("bytes1",  Schema.create(Type.BYTES   ), null, (Object)null));
-    fields.add(new Field("bytes2",  Schema.create(Type.BYTES   ), null, (Object)null));
+    fields.add(new Field("bytes1",  Schema.create(Type.BYTES   ), null, null));
+    fields.add(new Field("bytes2",  Schema.create(Type.BYTES   ), null, null));
 
-    fields.add(new Field("int1",    Schema.create(Type.INT     ), null, (Object)null));
-    fields.add(new Field("int2",    Schema.create(Type.INT     ), null, (Object)null));
+    fields.add(new Field("int1",    Schema.create(Type.INT     ), null, null));
+    fields.add(new Field("int2",    Schema.create(Type.INT     ), null, null));
 
-    fields.add(new Field("long1",   Schema.create(Type.LONG    ), null, (Object)null));
-    fields.add(new Field("long2",   Schema.create(Type.LONG    ), null, (Object)null));
+    fields.add(new Field("long1",   Schema.create(Type.LONG    ), null, null));
+    fields.add(new Field("long2",   Schema.create(Type.LONG    ), null, null));
 
-    fields.add(new Field("float1",  Schema.create(Type.FLOAT   ), null, (Object)null));
-    fields.add(new Field("float2",  Schema.create(Type.FLOAT   ), null, (Object)null));
+    fields.add(new Field("float1",  Schema.create(Type.FLOAT   ), null, null));
+    fields.add(new Field("float2",  Schema.create(Type.FLOAT   ), null, null));
 
-    fields.add(new Field("double1", Schema.create(Type.DOUBLE  ), null, (Object)null));
-    fields.add(new Field("double2", Schema.create(Type.DOUBLE  ), null, (Object)null));
+    fields.add(new Field("double1", Schema.create(Type.DOUBLE  ), null, null));
+    fields.add(new Field("double2", Schema.create(Type.DOUBLE  ), null, null));
 
-    fields.add(new Field("boolean1",Schema.create(Type.BOOLEAN ), null, (Object)null));
-    fields.add(new Field("boolean2",Schema.create(Type.BOOLEAN ), null, (Object)null));
+    fields.add(new Field("boolean1",Schema.create(Type.BOOLEAN ), null, null));
+    fields.add(new Field("boolean2",Schema.create(Type.BOOLEAN ), null, null));
 
     List<String> enumValues = new ArrayList<>();
     enumValues.add("One");
     enumValues.add("Two");
     Schema enumSchema = Schema.createEnum("myEnum", null, null, enumValues);
-    fields.add(new Field("enum1", enumSchema, null, (Object)null));
-    fields.add(new Field("enum2", enumSchema, null, (Object)null));
+    fields.add(new Field("enum1", enumSchema, null, null));
+    fields.add(new Field("enum2", enumSchema, null, null));
 
     Schema recordSchema = SchemaBuilder.record("aRecord").fields().requiredString("myString").endRecord();
-    fields.add(new Field("record1", recordSchema, null, (Object)null));
-    fields.add(new Field("record2", recordSchema, null, (Object)null));
+    fields.add(new Field("record1", recordSchema, null, null));
+    fields.add(new Field("record2", recordSchema, null, null));
 
     Schema arraySchema = Schema.createArray(Schema.create(Type.STRING));
-    fields.add(new Field("array1", arraySchema, null, (Object)null));
-    fields.add(new Field("array2", arraySchema, null, (Object)null));
+    fields.add(new Field("array1", arraySchema, null, null));
+    fields.add(new Field("array2", arraySchema, null, null));
 
     Schema mapSchema = Schema.createMap(Schema.create(Type.STRING));
-    fields.add(new Field("map1", mapSchema, null, (Object)null));
-    fields.add(new Field("map2", mapSchema, null, (Object)null));
+    fields.add(new Field("map1", mapSchema, null, null));
+    fields.add(new Field("map2", mapSchema, null, null));
 
     Schema schema = Schema.createRecord("Foo", "test", "mytest", false);
     schema.setFields(fields);
@@ -654,7 +654,7 @@ public class TestGenericData {
     Schema placeholderSchema = Schema.createRecord("Placeholder", null, null, false);
     List<Schema.Field> placeholderFields = new ArrayList<>();
     placeholderFields.add( // at least one field is needed to be a valid schema
-      new Schema.Field("id", Schema.create(Schema.Type.LONG), null, (Object)null));
+      new Schema.Field("id", Schema.create(Schema.Type.LONG), null, null));
     placeholderSchema.setFields(placeholderFields);
 
     Referenceable idRef = new Referenceable("id");
@@ -667,15 +667,15 @@ public class TestGenericData {
     Reference parentRef = new Reference("parent");
 
     List<Schema.Field> childFields = new ArrayList<>();
-    childFields.add(new Schema.Field("c", Schema.create(Schema.Type.STRING), null, (Object)null));
-    childFields.add(new Schema.Field("parent", parentRefSchema, null, (Object)null));
+    childFields.add(new Schema.Field("c", Schema.create(Schema.Type.STRING), null, null));
+    childFields.add(new Schema.Field("parent", parentRefSchema, null, null));
     Schema childSchema = parentRef.addToSchema(
       Schema.createRecord("Child", null, null, false, childFields));
 
     List<Schema.Field> parentFields = new ArrayList<>();
-    parentFields.add(new Schema.Field("id", Schema.create(Schema.Type.LONG), null, (Object)null));
-    parentFields.add(new Schema.Field("p", Schema.create(Schema.Type.STRING), null, (Object)null));
-    parentFields.add(new Schema.Field("child", childSchema, null, (Object)null));
+    parentFields.add(new Schema.Field("id", Schema.create(Schema.Type.LONG), null, null));
+    parentFields.add(new Schema.Field("p", Schema.create(Schema.Type.STRING), null, null));
+    parentFields.add(new Schema.Field("child", childSchema, null, null));
     parentSchema.setFields(parentFields);
 
     Schema schema = idRef.addToSchema(parentSchema);
@@ -708,7 +708,7 @@ public class TestGenericData {
     GenericRecord record = new GenericData.Record( elementSchema );
     record.put("value", "string");
 
-    GenericArray<GenericRecord> list = new GenericData.Array<GenericRecord>(1, arraySchema);
+    GenericArray<GenericRecord> list = new GenericData.Array<>(1, arraySchema);
     list.add(record);
 
     list.reset();
diff --git a/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericDatumWriter.java b/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericDatumWriter.java
index e5d6001..7bfb900 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericDatumWriter.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericDatumWriter.java
@@ -75,12 +75,9 @@ public class TestGenericDatumWriter {
 
     // call write in another thread
     ExecutorService executor = Executors.newSingleThreadExecutor();
-    Future<Void> result = executor.submit(new Callable<Void>() {
-      @Override
-      public Void call() throws Exception {
-        w.write(a, e);
-        return null;
-      }
+    Future<Void> result = executor.submit(() -> {
+      w.write(a, e);
+      return null;
     });
     sizeWrittenSignal.await();
     // size has been written so now add an element to the array
@@ -113,12 +110,9 @@ public class TestGenericDatumWriter {
 
     // call write in another thread
     ExecutorService executor = Executors.newSingleThreadExecutor();
-    Future<Void> result = executor.submit(new Callable<Void>() {
-      @Override
-      public Void call() throws Exception {
-        w.write(m, e);
-        return null;
-      }
+    Future<Void> result = executor.submit(() -> {
+      w.write(m, e);
+      return null;
     });
     sizeWrittenSignal.await();
     // size has been written so now add an entry to the map
diff --git a/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericLogicalTypes.java b/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericLogicalTypes.java
index 6cab577..11b8454 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericLogicalTypes.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericLogicalTypes.java
@@ -22,10 +22,7 @@ import java.io.File;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.UUID;
+import java.util.*;
 
 import org.apache.avro.*;
 import org.apache.avro.file.DataFileReader;
@@ -192,17 +189,11 @@ public class TestGenericLogicalTypes {
 
   private <D> List<D> read(DatumReader<D> reader, File file) throws IOException {
     List<D> data = new ArrayList<>();
-    FileReader<D> fileReader = null;
 
-    try {
-      fileReader = new DataFileReader<>(file, reader);
+    try (FileReader<D> fileReader = new DataFileReader<>(file, reader)) {
       for (D datum : fileReader) {
         data.add(datum);
       }
-    } finally {
-      if (fileReader != null) {
-        fileReader.close();
-      }
     }
 
     return data;
@@ -216,15 +207,12 @@ public class TestGenericLogicalTypes {
   private <D> File write(GenericData model, Schema schema, D... data) throws IOException {
     File file = temp.newFile();
     DatumWriter<D> writer = model.createDatumWriter(schema);
-    DataFileWriter<D> fileWriter = new DataFileWriter<>(writer);
 
-    try {
+    try (DataFileWriter<D> fileWriter = new DataFileWriter<>(writer)) {
       fileWriter.create(schema, file);
       for (D datum : data) {
         fileWriter.append(datum);
       }
-    } finally {
-      fileWriter.close();
     }
 
     return file;
@@ -275,12 +263,12 @@ public class TestGenericLogicalTypes {
 
     // test nested in array
     Schema arraySchema = Schema.createArray(schema);
-    ArrayList array = new ArrayList(Arrays.asList(value));
+    ArrayList array = new ArrayList(Collections.singletonList(value));
     checkCopy(array, model.deepCopy(arraySchema, array), true);
 
     // test record nested in array
     Schema recordArraySchema = Schema.createArray(recordSchema);
-    ArrayList recordArray = new ArrayList(Arrays.asList(record));
+    ArrayList recordArray = new ArrayList(Collections.singletonList(record));
     checkCopy(recordArray, model.deepCopy(recordArraySchema, recordArray), true);
   }
 
diff --git a/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericRecordBuilder.java b/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericRecordBuilder.java
index 2e1cec4..4d9539a 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericRecordBuilder.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericRecordBuilder.java
@@ -19,6 +19,7 @@ package org.apache.avro.generic;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 
 import org.apache.avro.AvroRuntimeException;
@@ -48,7 +49,7 @@ public class TestGenericRecordBuilder {
 
     // Set field in builder:
     builder.set("intField", 1);
-    List<String> anArray = Arrays.asList(new String[] { "one", "two", "three" });
+    List<String> anArray = Arrays.asList("one", "two", "three");
     builder.set("anArray", anArray);
     Assert.assertTrue("anArray should be set", builder.has("anArray"));
     Assert.assertEquals(anArray, builder.get("anArray"));
@@ -57,7 +58,7 @@ public class TestGenericRecordBuilder {
 
     // Build the record, and verify that fields are set:
     Record record = builder.build();
-    Assert.assertEquals(Integer.valueOf(1), record.get("intField"));
+    Assert.assertEquals(1, record.get("intField"));
     Assert.assertEquals(anArray, record.get("anArray"));
     Assert.assertNotNull(record.get("id"));
     Assert.assertEquals("0", record.get("id").toString());
@@ -86,7 +87,7 @@ public class TestGenericRecordBuilder {
   public void buildWithoutSettingRequiredFields2() {
     try {
       new GenericRecordBuilder(recordSchema()).
-      set("anArray", Arrays.asList(new String[] { "one" })).
+      set("anArray", Collections.singletonList("one")).
       build();
       Assert.fail("Should have thrown " +
           AvroRuntimeException.class.getCanonicalName());
diff --git a/lang/java/avro/src/test/java/org/apache/avro/io/TestBinaryDecoder.java b/lang/java/avro/src/test/java/org/apache/avro/io/TestBinaryDecoder.java
index a104fac..a2d5f6e 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/io/TestBinaryDecoder.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/io/TestBinaryDecoder.java
@@ -152,13 +152,12 @@ public class TestBinaryDecoder {
   }
 
   private static byte[] data = null;
-  private static int seed = -1;
   private static Schema schema = null;
   private static int count = 200;
   private static ArrayList<Object> records = new ArrayList<>(count);
   @BeforeClass
   public static void generateData() throws IOException {
-    seed = (int)System.currentTimeMillis();
+    int seed = (int) System.currentTimeMillis();
     // note some tests (testSkipping) rely on this explicitly
     String jsonSchema =
       "{\"type\": \"record\", \"name\": \"Test\", \"fields\": ["
diff --git a/lang/java/avro/src/test/java/org/apache/avro/io/TestBlockingIO.java b/lang/java/avro/src/test/java/org/apache/avro/io/TestBlockingIO.java
index 821c36b..71f7102 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/io/TestBlockingIO.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/io/TestBlockingIO.java
@@ -26,7 +26,6 @@ import java.nio.ByteBuffer;
 import java.util.ArrayDeque;
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.Stack;
 
 import com.fasterxml.jackson.core.JsonFactory;
 import com.fasterxml.jackson.core.JsonParser;
diff --git a/lang/java/avro/src/test/java/org/apache/avro/io/TestValidatingIO.java b/lang/java/avro/src/test/java/org/apache/avro/io/TestValidatingIO.java
index 2012632..83e4ecd 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/io/TestValidatingIO.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/io/TestValidatingIO.java
@@ -233,13 +233,13 @@ public class TestValidatingIO {
         result.add(r.nextInt());
         break;
       case 'L':
-        result.add(Long.valueOf(r.nextInt()));
+        result.add((long) r.nextInt());
         break;
       case 'F':
-        result.add(Float.valueOf(r.nextInt()));
+        result.add((float) r.nextInt());
         break;
       case 'D':
-        result.add(Double.valueOf(r.nextInt()));
+        result.add((double) r.nextInt());
         break;
       case 'S':
       case 'K':
diff --git a/lang/java/avro/src/test/java/org/apache/avro/io/parsing/TestResolvingGrammarGenerator.java b/lang/java/avro/src/test/java/org/apache/avro/io/parsing/TestResolvingGrammarGenerator.java
index f2157a2..f684e8c 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/io/parsing/TestResolvingGrammarGenerator.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/io/parsing/TestResolvingGrammarGenerator.java
@@ -129,12 +129,9 @@ public class TestResolvingGrammarGenerator {
   private byte[] writeRecord(Schema schema, GenericData.Record record) throws Exception {
     ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
     GenericDatumWriter<GenericData.Record> datumWriter = new GenericDatumWriter<>(schema);
-    DataFileWriter<GenericData.Record> writer = new DataFileWriter<>(datumWriter);
-    try {
+    try (DataFileWriter<GenericData.Record> writer = new DataFileWriter<>(datumWriter)) {
       writer.create(schema, byteStream);
       writer.append(record);
-    } finally {
-      writer.close();
     }
     return byteStream.toByteArray();
   }
@@ -142,11 +139,8 @@ public class TestResolvingGrammarGenerator {
   private GenericData.Record readRecord(Schema schema, byte[] data) throws Exception {
     ByteArrayInputStream byteStream = new ByteArrayInputStream(data);
     GenericDatumReader<GenericData.Record> datumReader = new GenericDatumReader<>(schema);
-    DataFileStream<GenericData.Record> reader = new DataFileStream<>(byteStream, datumReader);
-    try {
+    try (DataFileStream<GenericData.Record> reader = new DataFileStream<>(byteStream, datumReader)) {
       return reader.next();
-    } finally {
-      reader.close();
     }
   }
 }
diff --git a/lang/java/avro/src/test/java/org/apache/avro/io/parsing/TestResolvingGrammarGenerator2.java b/lang/java/avro/src/test/java/org/apache/avro/io/parsing/TestResolvingGrammarGenerator2.java
index f83c976..8a75f05 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/io/parsing/TestResolvingGrammarGenerator2.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/io/parsing/TestResolvingGrammarGenerator2.java
@@ -18,6 +18,7 @@
 package org.apache.avro.io.parsing;
 
 import java.util.Arrays;
+import java.util.Collections;
 
 import org.apache.avro.Schema;
 import org.apache.avro.SchemaBuilder;
@@ -75,7 +76,7 @@ public class TestResolvingGrammarGenerator2 {
         point3dNoDefault));
 
     new SchemaValidatorBuilder().canBeReadStrategy().validateAll()
-        .validate(point2dFullname, Arrays.asList(read));
+        .validate(point2dFullname, Collections.singletonList(read));
   }
 
   @Test
diff --git a/lang/java/avro/src/test/java/org/apache/avro/reflect/TestNonStringMapKeys.java b/lang/java/avro/src/test/java/org/apache/avro/reflect/TestNonStringMapKeys.java
index 589722c..d098cd0 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/reflect/TestNonStringMapKeys.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/reflect/TestNonStringMapKeys.java
@@ -80,14 +80,12 @@ public class TestNonStringMapKeys {
     log ("Read: " + co);
     assertNotNull (co.getEmployees());
     assertEquals (2, co.getEmployees().size());
-    Iterator<Entry<EmployeeId, EmployeeInfo>> itr = co.getEmployees().entrySet().iterator();
-    while (itr.hasNext()) {
-      Entry<EmployeeId, EmployeeInfo> e = itr.next();
+    for (Entry<EmployeeId, EmployeeInfo> e : co.getEmployees().entrySet()) {
       id = e.getKey().getId();
       name = e.getValue().getName();
-      assertTrue (
+      assertTrue(
         (id.equals(1) && name.equals("Foo")) ||
-        (id.equals(2) && name.equals("Bar"))
+          (id.equals(2) && name.equals("Bar"))
       );
     }
 
@@ -141,13 +139,11 @@ public class TestNonStringMapKeys {
     log ("Read: " + co);
     assertNotNull (co.getEmployees());
     assertEquals (1, co.getEmployees().size());
-    Iterator<Entry<Integer, EmployeeInfo2>> itr = co.getEmployees().entrySet().iterator();
-    while (itr.hasNext()) {
-      Entry<Integer, EmployeeInfo2> e = itr.next();
+    for (Entry<Integer, EmployeeInfo2> e : co.getEmployees().entrySet()) {
       Integer id = e.getKey();
       name = e.getValue().getName();
-      assertTrue (id.equals(11) && name.equals("Foo"));
-      assertEquals ("CompanyFoo", e.getValue().companyMap.values().iterator().next());
+      assertTrue(id.equals(11) && name.equals("Foo"));
+      assertEquals("CompanyFoo", e.getValue().companyMap.values().iterator().next());
     }
 
 
@@ -187,13 +183,11 @@ public class TestNonStringMapKeys {
     log ("Read: " + entity);
     assertNotNull (entity.getMap1());
     assertEquals (1, entity.getMap1().size());
-    Iterator<Entry<Integer, String>> itr = entity.getMap1().entrySet().iterator();
-    while (itr.hasNext()) {
-      Entry<Integer, String> e = itr.next();
+    for (Entry<Integer, String> e : entity.getMap1().entrySet()) {
       key = e.getKey();
       value = e.getValue();
-      assertEquals (1, key);
-      assertEquals ("Foo", value.toString());
+      assertEquals(1, key);
+      assertEquals("Foo", value.toString());
     }
     assertEquals (entity.getMap1(), entity.getMap2());
     assertEquals (entity.getMap1(), entity.getMap3());
diff --git a/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java b/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java
index c875d22..8add7ec 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java
@@ -116,7 +116,7 @@ public class TestReflect {
     Schema s = new Schema.Parser().parse
       ("[\"null\", {\"type\":\"map\",\"values\":\"float\"}]");
     GenericData data = ReflectData.get();
-    HashMap<Utf8,Float> map = new HashMap<Utf8,Float>();
+    HashMap<Utf8,Float> map = new HashMap<>();
     map.put(new Utf8("foo"), 1.0f);
     assertEquals(1, data.resolveUnion(s, map));
   }
@@ -787,9 +787,7 @@ public class TestReflect {
       final SampleRecord other = (SampleRecord)obj;
       if (x != other.x)
         return false;
-      if (y != other.y)
-        return false;
-      return true;
+      return y == other.y;
     }
 
     public static class AnotherSampleRecord {
@@ -815,13 +813,10 @@ public class TestReflect {
       public boolean equals(Object other) {
         if (other instanceof AnotherSampleRecord) {
           AnotherSampleRecord o = (AnotherSampleRecord) other;
-          if ( (this.a == null && o.a != null) ||
-               (this.a != null && !this.a.equals(o.a)) ||
-               (this.s == null && o.s != null) ||
-               (this.s != null && !this.s.equals(o.s)) ) {
-            return false;
-          }
-          return true;
+          return (this.a != null || o.a == null) &&
+            (this.a == null || this.a.equals(o.a)) &&
+            (this.s != null || o.s == null) &&
+            (this.s == null || this.s.equals(o.s));
         } else {
           return false;
         }
diff --git a/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflectDatumReader.java b/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflectDatumReader.java
index ceb7ecc..0cda841 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflectDatumReader.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflectDatumReader.java
@@ -121,11 +121,8 @@ public class TestReflectDatumReader {
       if (id != other.id)
         return false;
       if (relatedIds == null) {
-        if (other.relatedIds != null)
-          return false;
-      } else if (!relatedIds.equals(other.relatedIds))
-        return false;
-      return true;
+        return other.relatedIds == null;
+      } else return relatedIds.equals(other.relatedIds);
     }
   }
 
@@ -169,9 +166,7 @@ public class TestReflectDatumReader {
       PojoWithArray other = (PojoWithArray) obj;
       if (id != other.id)
         return false;
-      if (!Arrays.equals(relatedIds, other.relatedIds))
-        return false;
-      return true;
+      return Arrays.equals(relatedIds, other.relatedIds);
     }
 
   }
diff --git a/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflectLogicalTypes.java b/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflectLogicalTypes.java
index 356afe3..e754a05 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflectLogicalTypes.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflectLogicalTypes.java
@@ -21,10 +21,7 @@ package org.apache.avro.reflect;
 import java.io.File;
 import java.io.IOException;
 import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.UUID;
+import java.util.*;
 
 import org.apache.avro.*;
 import org.apache.avro.file.DataFileReader;
@@ -126,7 +123,7 @@ public class TestReflectLogicalTypes {
 
     File test = write(REFLECT, schema, record);
     Assert.assertEquals("Should match the decimal after round trip",
-        Arrays.asList(record),
+      Collections.singletonList(record),
         read(REFLECT.createDatumReader(schema), test));
   }
 
@@ -185,7 +182,7 @@ public class TestReflectLogicalTypes {
 
     File test = write(REFLECT, schema, record);
     Assert.assertEquals("Should match the decimal after round trip",
-        Arrays.asList(record),
+      Collections.singletonList(record),
         read(REFLECT.createDatumReader(schema), test));
   }
 
@@ -218,14 +215,9 @@ public class TestReflectLogicalTypes {
       }
 
       if (second == null) {
-        if (that.second != null) {
-          return false;
-        }
-      } else if (second.equals(that.second)) {
-        return false;
-      }
+        return that.second == null;
+      } else return !second.equals(that.second);
 
-      return true;
     }
 
     @Override
@@ -696,17 +688,11 @@ public class TestReflectLogicalTypes {
 
   private static <D> List<D> read(DatumReader<D> reader, File file) throws IOException {
     List<D> data = new ArrayList<>();
-    FileReader<D> fileReader = null;
 
-    try {
-      fileReader = new DataFileReader<>(file, reader);
+    try (FileReader<D> fileReader = new DataFileReader<>(file, reader)) {
       for (D datum : fileReader) {
         data.add(datum);
       }
-    } finally {
-      if (fileReader != null) {
-        fileReader.close();
-      }
     }
 
     return data;
@@ -720,15 +706,12 @@ public class TestReflectLogicalTypes {
   private <D> File write(GenericData model, Schema schema, D... data) throws IOException {
     File file = temp.newFile();
     DatumWriter<D> writer = model.createDatumWriter(schema);
-    DataFileWriter<D> fileWriter = new DataFileWriter<>(writer);
 
-    try {
+    try (DataFileWriter<D> fileWriter = new DataFileWriter<>(writer)) {
       fileWriter.create(schema, file);
       for (D datum : data) {
         fileWriter.append(datum);
       }
-    } finally {
-      fileWriter.close();
     }
 
     return file;
diff --git a/lang/java/compiler/src/main/java/org/apache/avro/compiler/schema/Schemas.java b/lang/java/compiler/src/main/java/org/apache/avro/compiler/schema/Schemas.java
index ae69c29..9ab0034 100644
--- a/lang/java/compiler/src/main/java/org/apache/avro/compiler/schema/Schemas.java
+++ b/lang/java/compiler/src/main/java/org/apache/avro/compiler/schema/Schemas.java
@@ -187,25 +187,13 @@ public final class Schemas {
     SchemaVisitorAction action = visitor.visitNonTerminal(schema);
     switch (action) {
       case CONTINUE:
-        dq.addLast(new Supplier<SchemaVisitorAction>() {
-          @Override
-          public SchemaVisitorAction get() {
-            return visitor.afterVisitNonTerminal(schema);
-          }
-        });
-        Iterator<Schema> it = itSupp.iterator();
-        while (it.hasNext()) {
-          Schema child = it.next();
+        dq.addLast((Supplier<SchemaVisitorAction>) () -> visitor.afterVisitNonTerminal(schema));
+        for (Schema child : itSupp) {
           dq.addLast(child);
         }
         break;
       case SKIP_SUBTREE:
-        dq.addLast(new Supplier<SchemaVisitorAction>() {
-          @Override
-          public SchemaVisitorAction get() {
-            return visitor.afterVisitNonTerminal(schema);
-          }
-        });
+        dq.addLast((Supplier<SchemaVisitorAction>) () -> visitor.afterVisitNonTerminal(schema));
         break;
       case SKIP_SIBLINGS:
         while (!dq.isEmpty() && dq.getLast() instanceof Schema) {
diff --git a/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/ProtocolTask.java b/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/ProtocolTask.java
index 02a1af0..73a533a 100644
--- a/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/ProtocolTask.java
+++ b/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/ProtocolTask.java
@@ -76,13 +76,12 @@ public class ProtocolTask extends Task {
       compile(src);
 
     Project myProject = getProject();
-    for (int i = 0; i < filesets.size(); i++) {
-      FileSet fs = filesets.get(i);
+    for (FileSet fs : filesets) {
       DirectoryScanner ds = fs.getDirectoryScanner(myProject);
       File dir = fs.getDir(myProject);
       String[] srcs = ds.getIncludedFiles();
-      for (int j = 0; j < srcs.length; j++) {
-        compile(new File(dir, srcs[j]));
+      for (String src1 : srcs) {
+        compile(new File(dir, src1));
       }
     }
   }
@@ -97,9 +96,7 @@ public class ProtocolTask extends Task {
   private void compile(File file) {
     try {
       doCompile(file, dest);
-    } catch (AvroRuntimeException e) {
-      throw new BuildException(e);
-    } catch (IOException e) {
+    } catch (AvroRuntimeException | IOException e) {
       throw new BuildException(e);
     }
   }
diff --git a/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java b/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
index a6e8ae6..6269a50 100644
--- a/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
+++ b/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
@@ -845,7 +845,7 @@ public class SpecificCompiler {
     * logic in record.vm can handle the schema being presented. */
   public boolean isCustomCodable(Schema schema) {
     if (schema.isError()) return false;
-    return isCustomCodable(schema, new HashSet<Schema>());
+    return isCustomCodable(schema, new HashSet<>());
   }
 
   private boolean isCustomCodable(Schema schema, Set<Schema> seen) {
@@ -909,10 +909,10 @@ public class SpecificCompiler {
       return new String[] { value.toString() };
     if (value instanceof List) {
       List<?> list = (List<?>) value;
-      List<String> annots = new ArrayList<String>();
+      List<String> annots = new ArrayList<>();
       for (Object o : list)
         annots.add(o.toString());
-      return annots.toArray(new String[annots.size()]);
+      return annots.toArray(new String[0]);
     }
     return new String[0];
   }
diff --git a/lang/java/compiler/src/test/java/org/apache/avro/compiler/idl/TestCycle.java b/lang/java/compiler/src/test/java/org/apache/avro/compiler/idl/TestCycle.java
index 278aa2a..491704c 100644
--- a/lang/java/compiler/src/test/java/org/apache/avro/compiler/idl/TestCycle.java
+++ b/lang/java/compiler/src/test/java/org/apache/avro/compiler/idl/TestCycle.java
@@ -19,7 +19,6 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
@@ -80,7 +79,7 @@ public class TestCycle {
 
     GenericRecordBuilder rb = new GenericRecordBuilder(schemas.get("SampleNode"));
     rb.set("count", 10);
-    rb.set("subNodes", Arrays.asList(sp));
+    rb.set("subNodes", Collections.singletonList(sp));
     GenericData.Record record = rb.build();
 
     serDeserRecord(record);
diff --git a/lang/java/compiler/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java b/lang/java/compiler/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
index 51f4b7b..d15a0e7 100644
--- a/lang/java/compiler/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
+++ b/lang/java/compiler/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
@@ -109,7 +109,7 @@ public class TestSpecificCompiler {
     };
     JavaCompiler.CompilationTask cTask = compiler.getTask(null, fileManager,
             diagnosticListener, Collections.singletonList("-Xlint:all"), null,
-            fileManager.getJavaFileObjects(javaFiles.toArray(new File[javaFiles.size()])));
+            fileManager.getJavaFileObjects(javaFiles.toArray(new File[0])));
     boolean compilesWithoutError = cTask.call();
     assertTrue(compilesWithoutError);
     assertEquals("Warnings produced when compiling generated code with -Xlint:all", 0, warnings.size());
diff --git a/lang/java/grpc/src/main/java/org/apache/avro/grpc/ServiceDescriptor.java b/lang/java/grpc/src/main/java/org/apache/avro/grpc/ServiceDescriptor.java
index d9fa97a..fd8240c 100644
--- a/lang/java/grpc/src/main/java/org/apache/avro/grpc/ServiceDescriptor.java
+++ b/lang/java/grpc/src/main/java/org/apache/avro/grpc/ServiceDescriptor.java
@@ -33,7 +33,6 @@ class ServiceDescriptor {
   // cache for service descriptors.
   private static final ConcurrentMap<String, ServiceDescriptor> SERVICE_DESCRIPTORS =
       new ConcurrentHashMap<>();
-  private final Class iface;
   private final String serviceName;
   private final Protocol protocol;
   // cache for method descriptors.
@@ -41,7 +40,7 @@ class ServiceDescriptor {
       new ConcurrentHashMap<>();
 
   private ServiceDescriptor(Class iface, String serviceName) {
-    this.iface = iface;
+    Class iface1 = iface;
     this.serviceName = serviceName;
     this.protocol = AvroGrpcUtils.getProtocol(iface);
   }
diff --git a/lang/java/grpc/src/test/java/org/apache/avro/grpc/TestAvroProtocolGrpc.java b/lang/java/grpc/src/test/java/org/apache/avro/grpc/TestAvroProtocolGrpc.java
index 436405c..1454918 100644
--- a/lang/java/grpc/src/test/java/org/apache/avro/grpc/TestAvroProtocolGrpc.java
+++ b/lang/java/grpc/src/test/java/org/apache/avro/grpc/TestAvroProtocolGrpc.java
@@ -111,13 +111,12 @@ public class TestAvroProtocolGrpc {
     Boolean val2 = true;
     long val3 = 123321L;
     int val4 = 42;
-    String result = stub.concatenate(val1, val2, val3, val4);
-    assertEquals(val1 + val2 + val3 + val4, result);
+    assertEquals(val1 + val2 + val3 + val4, stub.concatenate(val1, val2, val3, val4));
   }
 
   @Test
   public void testCallbackInterface() throws Exception {
-    CallFuture<TestRecord> future = new CallFuture<TestRecord>();
+    CallFuture<TestRecord> future = new CallFuture<>();
     callbackStub.echo(record, future);
     assertEquals(record, future.get(1, TimeUnit.SECONDS));
   }
@@ -166,8 +165,7 @@ public class TestAvroProtocolGrpc {
         return null;
       }
     });
-    String response = stub.concatenate("foo", true, 42L, 42);
-    assertEquals(null, response);
+    assertEquals(null, stub.concatenate("foo", true, 42L, 42));
   }
 
   @Test(expected = AvroRuntimeException.class)
diff --git a/lang/java/ipc-jetty/src/test/java/org/apache/avro/ipc/jetty/TestBulkData.java b/lang/java/ipc-jetty/src/test/java/org/apache/avro/ipc/jetty/TestBulkData.java
index 5b9add6..9d8d169 100644
--- a/lang/java/ipc-jetty/src/test/java/org/apache/avro/ipc/jetty/TestBulkData.java
+++ b/lang/java/ipc-jetty/src/test/java/org/apache/avro/ipc/jetty/TestBulkData.java
@@ -61,7 +61,6 @@ public class TestBulkData {
   }
 
   private static Server server;
-  private static Transceiver client;
   private static BulkData proxy;
 
   @Before
@@ -71,8 +70,7 @@ public class TestBulkData {
       new HttpServer(new SpecificResponder(BulkData.class, new BulkDataImpl()),
                      0);
     server.start();
-    client =
-      new HttpTransceiver(new URL("http://127.0.0.1:"+server.getPort()+"/"));
+    Transceiver client = new HttpTransceiver(new URL("http://127.0.0.1:" + server.getPort() + "/"));
     proxy = SpecificRequestor.getClient(BulkData.class, client);
   }
 
diff --git a/lang/java/ipc-netty/src/main/java/org/apache/avro/ipc/netty/NettyServer.java b/lang/java/ipc-netty/src/main/java/org/apache/avro/ipc/netty/NettyServer.java
index 3f146db..aa33deb 100644
--- a/lang/java/ipc-netty/src/main/java/org/apache/avro/ipc/netty/NettyServer.java
+++ b/lang/java/ipc-netty/src/main/java/org/apache/avro/ipc/netty/NettyServer.java
@@ -64,7 +64,6 @@ public class NettyServer implements Server {
       "avro-netty-server");
   private final ChannelFactory channelFactory;
   private final CountDownLatch closed = new CountDownLatch(1);
-  private final ExecutionHandler executionHandler;
 
   public NettyServer(Responder responder, InetSocketAddress addr) {
     this(responder, addr, new NioServerSocketChannelFactory
@@ -90,20 +89,17 @@ public class NettyServer implements Server {
                      final ExecutionHandler executionHandler) {
     this.responder = responder;
     this.channelFactory = channelFactory;
-    this.executionHandler = executionHandler;
+    ExecutionHandler executionHandler1 = executionHandler;
     ServerBootstrap bootstrap = new ServerBootstrap(channelFactory);
-    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
-      @Override
-      public ChannelPipeline getPipeline() throws Exception {
-        ChannelPipeline p = pipelineFactory.getPipeline();
-        p.addLast("frameDecoder", new NettyFrameDecoder());
-        p.addLast("frameEncoder", new NettyFrameEncoder());
-        if (executionHandler != null) {
-          p.addLast("executionHandler", executionHandler);
-        }
-        p.addLast("handler", new NettyServerAvroHandler());
-        return p;
+    bootstrap.setPipelineFactory(() -> {
+      ChannelPipeline p = pipelineFactory.getPipeline();
+      p.addLast("frameDecoder", new NettyFrameDecoder());
+      p.addLast("frameEncoder", new NettyFrameEncoder());
+      if (executionHandler != null) {
+        p.addLast("executionHandler", executionHandler);
       }
+      p.addLast("handler", new NettyServerAvroHandler());
+      return p;
     });
     serverChannel = bootstrap.bind(addr);
     allChannels.add(serverChannel);
@@ -118,12 +114,7 @@ public class NettyServer implements Server {
   public NettyServer(Responder responder, InetSocketAddress addr,
                      ChannelFactory channelFactory,
                      final ExecutionHandler executionHandler) {
-    this(responder, addr, channelFactory, new ChannelPipelineFactory() {
-      @Override
-      public ChannelPipeline getPipeline() throws Exception {
-        return Channels.pipeline();
-      }
-    }, executionHandler);
+    this(responder, addr, channelFactory, Channels::pipeline, executionHandler);
   }
 
   @Override
diff --git a/lang/java/ipc-netty/src/main/java/org/apache/avro/ipc/netty/NettyTransceiver.java b/lang/java/ipc-netty/src/main/java/org/apache/avro/ipc/netty/NettyTransceiver.java
index ad4c48a..57e82d0 100644
--- a/lang/java/ipc-netty/src/main/java/org/apache/avro/ipc/netty/NettyTransceiver.java
+++ b/lang/java/ipc-netty/src/main/java/org/apache/avro/ipc/netty/NettyTransceiver.java
@@ -46,7 +46,6 @@ import org.jboss.netty.channel.ChannelFuture;
 import org.jboss.netty.channel.ChannelFutureListener;
 import org.jboss.netty.channel.ChannelHandlerContext;
 import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.channel.ChannelPipelineFactory;
 import org.jboss.netty.channel.ChannelState;
 import org.jboss.netty.channel.ChannelStateEvent;
 import org.jboss.netty.channel.ChannelUpstreamHandler;
@@ -186,15 +185,12 @@ public class NettyTransceiver extends Transceiver {
     remoteAddr = addr;
 
     // Configure the event pipeline factory.
-    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
-      @Override
-      public ChannelPipeline getPipeline() throws Exception {
-        ChannelPipeline p = Channels.pipeline();
-        p.addLast("frameDecoder", new NettyFrameDecoder());
-        p.addLast("frameEncoder", new NettyFrameEncoder());
-        p.addLast("handler", createNettyClientAvroHandler());
-        return p;
-      }
+    bootstrap.setPipelineFactory(() -> {
+      ChannelPipeline p = Channels.pipeline();
+      p.addLast("frameDecoder", new NettyFrameDecoder());
+      p.addLast("frameEncoder", new NettyFrameEncoder());
+      p.addLast("handler", createNettyClientAvroHandler());
+      return p;
     });
 
     if (nettyClientBootstrapOptions != null) {
@@ -459,10 +455,7 @@ public class NettyTransceiver extends Transceiver {
       CallFuture<List<ByteBuffer>> transceiverFuture = new CallFuture<>();
       transceive(request, transceiverFuture);
       return transceiverFuture.get();
-    } catch (InterruptedException e) {
-      LOG.debug("failed to get the response", e);
-      return null;
-    } catch (ExecutionException e) {
+    } catch (InterruptedException | ExecutionException e) {
       LOG.debug("failed to get the response", e);
       return null;
     }
diff --git a/lang/java/ipc-netty/src/main/java/org/apache/avro/ipc/netty/NettyTransportCodec.java b/lang/java/ipc-netty/src/main/java/org/apache/avro/ipc/netty/NettyTransportCodec.java
index 432fe28..17dcce0 100644
--- a/lang/java/ipc-netty/src/main/java/org/apache/avro/ipc/netty/NettyTransportCodec.java
+++ b/lang/java/ipc-netty/src/main/java/org/apache/avro/ipc/netty/NettyTransportCodec.java
@@ -92,7 +92,7 @@ public class NettyTransportCodec {
       }
 
       return ChannelBuffers
-          .wrappedBuffer(bbs.toArray(new ByteBuffer[bbs.size()]));
+          .wrappedBuffer(bbs.toArray(new ByteBuffer[0]));
     }
 
     private ByteBuffer getPackHeader(NettyDataPack dataPack) {
diff --git a/lang/java/ipc-netty/src/test/java/org/apache/avro/ipc/netty/NettyTransceiverWhenFailsToConnect.java b/lang/java/ipc-netty/src/test/java/org/apache/avro/ipc/netty/NettyTransceiverWhenFailsToConnect.java
index 60196bc..5f58976 100644
--- a/lang/java/ipc-netty/src/test/java/org/apache/avro/ipc/netty/NettyTransceiverWhenFailsToConnect.java
+++ b/lang/java/ipc-netty/src/test/java/org/apache/avro/ipc/netty/NettyTransceiverWhenFailsToConnect.java
@@ -27,7 +27,7 @@ import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.net.ServerSocket;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 
 /**
  * This is a very specific test that verifies that if the NettyTransceiver fails
@@ -37,35 +37,29 @@ public class NettyTransceiverWhenFailsToConnect {
 
     @Test(expected = IOException.class)
     public void testNettyTransceiverReleasesNettyChannelOnFailingToConnect() throws Exception {
-        ServerSocket serverSocket = null;
-        LastChannelRememberingChannelFactory socketChannelFactory = null;
 
-        try {
-            serverSocket = new ServerSocket(0);
-            socketChannelFactory = new LastChannelRememberingChannelFactory();
+      LastChannelRememberingChannelFactory socketChannelFactory = null;
+      try (ServerSocket serverSocket = new ServerSocket(0)) {
+        socketChannelFactory = new LastChannelRememberingChannelFactory();
 
-            try {
-                new NettyTransceiver(
-                        new InetSocketAddress(serverSocket.getLocalPort()),
-                        socketChannelFactory,
-                        1L
-                );
-            } finally {
-                assertEquals("expected that the channel opened by the transceiver is closed",
-                        false, socketChannelFactory.lastChannel.isOpen());
-            }
+        try {
+          new NettyTransceiver(
+            new InetSocketAddress(serverSocket.getLocalPort()),
+            socketChannelFactory,
+            1L
+          );
         } finally {
+          assertFalse("expected that the channel opened by the transceiver is closed", socketChannelFactory.lastChannel.isOpen());
+        }
+      } finally {
 
-            if (serverSocket != null) {
-                // closing the server socket will actually free up the open channel in the
-                // transceiver, which would have hung otherwise (pre AVRO-1407)
-                serverSocket.close();
-            }
+        // closing the server socket will actually free up the open channel in the
+        // transceiver, which would have hung otherwise (pre AVRO-1407)
 
-            if (socketChannelFactory != null) {
-                socketChannelFactory.releaseExternalResources();
-            }
+        if (socketChannelFactory != null) {
+          socketChannelFactory.releaseExternalResources();
         }
+      }
     }
 
     class LastChannelRememberingChannelFactory extends NioClientSocketChannelFactory implements ChannelFactory {
diff --git a/lang/java/ipc-netty/src/test/java/org/apache/avro/ipc/netty/TestNettyServerWithCallbacks.java b/lang/java/ipc-netty/src/test/java/org/apache/avro/ipc/netty/TestNettyServerWithCallbacks.java
index 127f41b..319d2d0 100644
--- a/lang/java/ipc-netty/src/test/java/org/apache/avro/ipc/netty/TestNettyServerWithCallbacks.java
+++ b/lang/java/ipc-netty/src/test/java/org/apache/avro/ipc/netty/TestNettyServerWithCallbacks.java
@@ -273,9 +273,8 @@ public class TestNettyServerWithCallbacks {
       int serverPort = server2.getPort();
       System.out.println("server2 port : " + serverPort);
 
-      Transceiver transceiver2 = new NettyTransceiver(new InetSocketAddress(
-          serverPort), TestNettyServer.CONNECT_TIMEOUT_MILLIS);
-      try {
+      try (Transceiver transceiver2 = new NettyTransceiver(new InetSocketAddress(
+        serverPort), TestNettyServer.CONNECT_TIMEOUT_MILLIS)) {
         Simple.Callback simpleClient2 =
           SpecificRequestor.getClient(Simple.Callback.class, transceiver2);
 
@@ -321,8 +320,6 @@ public class TestNettyServerWithCallbacks {
           throw e;
         }
         Assert.assertTrue("Expected IOException", ioeCaught);
-      } finally {
-        transceiver2.close();
       }
     } finally {
       server2.close();
@@ -342,9 +339,8 @@ public class TestNettyServerWithCallbacks {
       System.out.println("server2 port : " + serverPort);
 
       CallFuture<Integer> addFuture = new CallFuture<>();
-      Transceiver transceiver2 = new NettyTransceiver(new InetSocketAddress(
-          serverPort), TestNettyServer.CONNECT_TIMEOUT_MILLIS);
-      try {
+      try (Transceiver transceiver2 = new NettyTransceiver(new InetSocketAddress(
+        serverPort), TestNettyServer.CONNECT_TIMEOUT_MILLIS)) {
         Simple.Callback simpleClient2 =
           SpecificRequestor.getClient(Simple.Callback.class, transceiver2);
 
@@ -354,11 +350,9 @@ public class TestNettyServerWithCallbacks {
         // Now acquire the semaphore so that the server will block:
         blockingSimpleImpl.acquireRunPermit();
         simpleClient2.add(1, 2, addFuture);
-      } finally {
-        // When the transceiver is closed, the CallFuture should get
-        // an IOException
-        transceiver2.close();
       }
+      // When the transceiver is closed, the CallFuture should get
+      // an IOException
       boolean ioeThrown = false;
       try {
         addFuture.get();
@@ -411,15 +405,12 @@ public class TestNettyServerWithCallbacks {
       blockingSimpleImpl.acquireRunPermit();
 
       // Start client call
-      Future<?> clientFuture = Executors.newSingleThreadExecutor().submit(new Runnable() {
-        @Override
-        public void run() {
-          try {
-            simpleClient2.add(3, 4);
-            Assert.fail("Expected an exception");
-          } catch (Exception e) {
-            // expected
-          }
+      Future<?> clientFuture = Executors.newSingleThreadExecutor().submit(() -> {
+        try {
+          simpleClient2.add(3, 4);
+          Assert.fail("Expected an exception");
+        } catch (Exception e) {
+          // expected
         }
       });
 
@@ -431,12 +422,7 @@ public class TestNettyServerWithCallbacks {
 
       // Stop the server in a separate thread as it blocks the actual thread until the server side
       // method is running
-      new Thread(new Runnable() {
-        @Override
-        public void run() {
-          server2.close();
-        }
-      }).start();
+      new Thread(server2::close).start();
 
       // With the server gone, we expect the client to get some exception and exit
       // Wait for the client call to exit
@@ -509,19 +495,16 @@ public class TestNettyServerWithCallbacks {
     final AtomicBoolean runFlag = new AtomicBoolean(true);
     final CountDownLatch startLatch = new CountDownLatch(threadCount);
     for (int ii = 0; ii < threadCount; ii++) {
-      threadPool.submit(new Runnable() {
-        @Override
-        public void run() {
-          try {
-            startLatch.countDown();
-            startLatch.await(2, TimeUnit.SECONDS);
-            while (runFlag.get()) {
-              rpcCount.incrementAndGet();
-              Assert.assertEquals("Hello, World!", simpleClient.hello("World!"));
-            }
-          } catch (Exception e) {
-            e.printStackTrace();
+      threadPool.submit(() -> {
+        try {
+          startLatch.countDown();
+          startLatch.await(2, TimeUnit.SECONDS);
+          while (runFlag.get()) {
+            rpcCount.incrementAndGet();
+            Assert.assertEquals("Hello, World!", simpleClient.hello("World!"));
           }
+        } catch (Exception e) {
+          e.printStackTrace();
         }
       });
     }
diff --git a/lang/java/ipc-netty/src/test/java/org/apache/avro/ipc/netty/TestNettyTransceiverWhenServerStops.java b/lang/java/ipc-netty/src/test/java/org/apache/avro/ipc/netty/TestNettyTransceiverWhenServerStops.java
index a191e87..aa63871 100644
--- a/lang/java/ipc-netty/src/test/java/org/apache/avro/ipc/netty/TestNettyTransceiverWhenServerStops.java
+++ b/lang/java/ipc-netty/src/test/java/org/apache/avro/ipc/netty/TestNettyTransceiverWhenServerStops.java
@@ -51,22 +51,19 @@ public class TestNettyTransceiverWhenServerStops {
 
     // Start a bunch of client threads that use the transceiver to send messages
     for (int i = 0; i < 100; i++) {
-      Thread thread = new Thread(new Runnable() {
-          @Override
-            public void run() {
-            while (true) {
-              try {
-                mail.send(createMessage());
-                successes.incrementAndGet();
-              } catch (Exception e) {
-                failures.incrementAndGet();
-                if (quitOnFailure.get()) {
-                  return;
-                }
-              }
+      Thread thread = new Thread(() -> {
+        while (true) {
+          try {
+            mail.send(createMessage());
+            successes.incrementAndGet();
+          } catch (Exception e) {
+            failures.incrementAndGet();
+            if (quitOnFailure.get()) {
+              return;
             }
           }
-        });
+        }
+      });
       threads.add(thread);
       thread.start();
     }
diff --git a/lang/java/ipc/src/main/java/org/apache/avro/ipc/HttpTransceiver.java b/lang/java/ipc/src/main/java/org/apache/avro/ipc/HttpTransceiver.java
index cf17a27..e77a28b 100644
--- a/lang/java/ipc/src/main/java/org/apache/avro/ipc/HttpTransceiver.java
+++ b/lang/java/ipc/src/main/java/org/apache/avro/ipc/HttpTransceiver.java
@@ -53,11 +53,8 @@ public class HttpTransceiver extends Transceiver {
 
   @Override
   public synchronized List<ByteBuffer> readBuffers() throws IOException {
-    InputStream in = connection.getInputStream();
-    try {
+    try (InputStream in = connection.getInputStream()) {
       return readBuffers(in);
-    } finally {
-      in.close();
     }
   }
 
@@ -77,11 +74,8 @@ public class HttpTransceiver extends Transceiver {
     connection.setReadTimeout(timeout);
     connection.setConnectTimeout(timeout);
 
-    OutputStream out = connection.getOutputStream();
-    try {
+    try (OutputStream out = connection.getOutputStream()) {
       writeBuffers(buffers, out);
-    } finally {
-      out.close();
     }
   }
 
diff --git a/lang/java/ipc/src/main/java/org/apache/avro/ipc/SaslSocketTransceiver.java b/lang/java/ipc/src/main/java/org/apache/avro/ipc/SaslSocketTransceiver.java
index 7d512e1..1cb344e 100644
--- a/lang/java/ipc/src/main/java/org/apache/avro/ipc/SaslSocketTransceiver.java
+++ b/lang/java/ipc/src/main/java/org/apache/avro/ipc/SaslSocketTransceiver.java
@@ -252,7 +252,7 @@ public class SaslSocketTransceiver extends Transceiver {
     zeroHeader.flip();                            // zero-terminate
     writes.add(zeroHeader);
 
-    writeFully(writes.toArray(new ByteBuffer[writes.size()]));
+    writeFully(writes.toArray(new ByteBuffer[0]));
   }
 
   private void write(Status status, String prefix, ByteBuffer response)
diff --git a/lang/java/ipc/src/main/java/org/apache/avro/ipc/SocketServer.java b/lang/java/ipc/src/main/java/org/apache/avro/ipc/SocketServer.java
index 2747484..d14c859 100644
--- a/lang/java/ipc/src/main/java/org/apache/avro/ipc/SocketServer.java
+++ b/lang/java/ipc/src/main/java/org/apache/avro/ipc/SocketServer.java
@@ -120,10 +120,7 @@ public class SocketServer extends Thread implements Server {
           while (true) {
             xc.writeBuffers(responder.respond(xc.readBuffers(), xc));
           }
-        } catch (EOFException e) {
-          return;
-        } catch (ClosedChannelException e) {
-          return;
+        } catch (EOFException | ClosedChannelException e) {
         } finally {
           xc.close();
         }
diff --git a/lang/java/ipc/src/main/java/org/apache/avro/ipc/specific/SpecificRequestor.java b/lang/java/ipc/src/main/java/org/apache/avro/ipc/specific/SpecificRequestor.java
index 1bd1fd5..e801a9d 100644
--- a/lang/java/ipc/src/main/java/org/apache/avro/ipc/specific/SpecificRequestor.java
+++ b/lang/java/ipc/src/main/java/org/apache/avro/ipc/specific/SpecificRequestor.java
@@ -73,66 +73,63 @@ public class SpecificRequestor extends Requestor implements InvocationHandler {
   public Object invoke(Object proxy, Method method, Object[] args)
     throws Throwable {
     String name = method.getName();
-    if (name.equals("hashCode")) {
-      return hashCode();
-    }
-    else if (name.equals("equals")) {
-      Object obj = args[0];
-      return (proxy == obj) || (obj != null && Proxy.isProxyClass(obj.getClass())
-                                && this.equals(Proxy.getInvocationHandler(obj)));
-    }
-    else if (name.equals("toString")) {
-      String protocol = "unknown";
-      String remote = "unknown";
-      Class<?>[] interfaces = proxy.getClass().getInterfaces();
-      if (interfaces.length > 0) {
-        try {
-          protocol = Class.forName(interfaces[0].getName()).getSimpleName();
-        } catch (ClassNotFoundException e) {
-        }
-
-        InvocationHandler handler = Proxy.getInvocationHandler(proxy);
-        if (handler instanceof Requestor) {
+    switch (name) {
+      case "hashCode":
+        return hashCode();
+      case "equals":
+        Object obj = args[0];
+        return (proxy == obj) || (obj != null && Proxy.isProxyClass(obj.getClass())
+          && this.equals(Proxy.getInvocationHandler(obj)));
+      case "toString":
+        String protocol = "unknown";
+        String remote = "unknown";
+        Class<?>[] interfaces = proxy.getClass().getInterfaces();
+        if (interfaces.length > 0) {
           try {
-            remote = ((Requestor) handler).getTransceiver().getRemoteName();
-          } catch (IOException e) {
+            protocol = Class.forName(interfaces[0].getName()).getSimpleName();
+          } catch (ClassNotFoundException e) {
+          }
+
+          InvocationHandler handler = Proxy.getInvocationHandler(proxy);
+          if (handler instanceof Requestor) {
+            try {
+              remote = ((Requestor) handler).getTransceiver().getRemoteName();
+            } catch (IOException e) {
+            }
           }
         }
-      }
-      return "Proxy[" + protocol + "," + remote + "]";
-    }
-    else {
-      try {
-        // Check if this is a callback-based RPC:
-        Type[] parameterTypes = method.getParameterTypes();
-        if ((parameterTypes.length > 0) &&
+        return "Proxy[" + protocol + "," + remote + "]";
+      default:
+        try {
+          // Check if this is a callback-based RPC:
+          Type[] parameterTypes = method.getParameterTypes();
+          if ((parameterTypes.length > 0) &&
             (parameterTypes[parameterTypes.length - 1] instanceof Class) &&
-            Callback.class.isAssignableFrom(((Class<?>)parameterTypes[parameterTypes.length - 1]))) {
-          // Extract the Callback from the end of of the argument list
-          Object[] finalArgs = Arrays.copyOf(args, args.length - 1);
-          Callback<?> callback = (Callback<?>)args[args.length - 1];
-          request(method.getName(), finalArgs, callback);
-          return null;
-        }
-        else {
-          return request(method.getName(), args);
-        }
-      } catch (Exception e) {
-        // Check if this is a declared Exception:
-        for (Class<?> exceptionClass : method.getExceptionTypes()) {
-          if (exceptionClass.isAssignableFrom(e.getClass())) {
+            Callback.class.isAssignableFrom(((Class<?>) parameterTypes[parameterTypes.length - 1]))) {
+            // Extract the Callback from the end of of the argument list
+            Object[] finalArgs = Arrays.copyOf(args, args.length - 1);
+            Callback<?> callback = (Callback<?>) args[args.length - 1];
+            request(method.getName(), finalArgs, callback);
+            return null;
+          } else {
+            return request(method.getName(), args);
+          }
+        } catch (Exception e) {
+          // Check if this is a declared Exception:
+          for (Class<?> exceptionClass : method.getExceptionTypes()) {
+            if (exceptionClass.isAssignableFrom(e.getClass())) {
+              throw e;
+            }
+          }
+
+          // Next, check for RuntimeExceptions:
+          if (e instanceof RuntimeException) {
             throw e;
           }
-        }
 
-        // Next, check for RuntimeExceptions:
-        if (e instanceof RuntimeException) {
-          throw e;
+          // Not an expected Exception, so wrap it in AvroRemoteException:
+          throw new AvroRemoteException(e);
         }
-
-        // Not an expected Exception, so wrap it in AvroRemoteException:
-        throw new AvroRemoteException(e);
-      }
     }
   }
 
diff --git a/lang/java/ipc/src/main/java/org/apache/avro/ipc/specific/SpecificResponder.java b/lang/java/ipc/src/main/java/org/apache/avro/ipc/specific/SpecificResponder.java
index 1c8ca08..a96d1cb 100644
--- a/lang/java/ipc/src/main/java/org/apache/avro/ipc/specific/SpecificResponder.java
+++ b/lang/java/ipc/src/main/java/org/apache/avro/ipc/specific/SpecificResponder.java
@@ -95,9 +95,7 @@ public class SpecificResponder extends GenericResponder {
       } else {
         throw new Exception(e.getTargetException());
       }
-    } catch (NoSuchMethodException e) {
-      throw new AvroRuntimeException(e);
-    } catch (IllegalAccessException e) {
+    } catch (NoSuchMethodException | IllegalAccessException e) {
       throw new AvroRuntimeException(e);
     }
   }
diff --git a/lang/java/ipc/src/main/java/org/apache/avro/ipc/stats/StatsServlet.java b/lang/java/ipc/src/main/java/org/apache/avro/ipc/stats/StatsServlet.java
index 8605095..bf9b601 100644
--- a/lang/java/ipc/src/main/java/org/apache/avro/ipc/stats/StatsServlet.java
+++ b/lang/java/ipc/src/main/java/org/apache/avro/ipc/stats/StatsServlet.java
@@ -36,8 +36,6 @@ import javax.servlet.http.HttpServletResponse;
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.VelocityEngine;
-import org.apache.velocity.exception.ParseErrorException;
-import org.apache.velocity.exception.ResourceNotFoundException;
 
 import org.apache.avro.Protocol.Message;
 import org.apache.avro.ipc.RPCContext;
@@ -159,10 +157,6 @@ public class StatsServlet extends HttpServlet {
     try {
       t = velocityEngine.getTemplate(
           "org/apache/avro/ipc/stats/templates/statsview.vm");
-    } catch (ResourceNotFoundException e) {
-      throw new IOException();
-    } catch (ParseErrorException e) {
-      throw new IOException();
     } catch (Exception e) {
       throw new IOException();
     }
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/TestCompare.java b/lang/java/ipc/src/test/java/org/apache/avro/TestCompare.java
index 6bcc76d..175476f 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/TestCompare.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/TestCompare.java
@@ -76,26 +76,26 @@ public class TestCompare {
 
   @Test
   public void testInt() throws Exception {
-    check("\"int\"", new Integer(-1), new Integer(0));
-    check("\"int\"", new Integer(0), new Integer(1));
+    check("\"int\"", -1, 0);
+    check("\"int\"", 0, 1);
   }
 
   @Test
   public void testLong() throws Exception {
-    check("\"long\"", new Long(11), new Long(12));
-    check("\"long\"", new Long(-1), new Long(1));
+    check("\"long\"", 11L, 12L);
+    check("\"long\"", (long) -1, 1L);
   }
 
   @Test
   public void testFloat() throws Exception {
-    check("\"float\"", new Float(1.1), new Float(1.2));
-    check("\"float\"", new Float(-1.1), new Float(1.0));
+    check("\"float\"", 1.1f, 1.2f);
+    check("\"float\"", (float) -1.1, 1.0f);
   }
 
   @Test
   public void testDouble() throws Exception {
-    check("\"double\"", new Double(1.2), new Double(1.3));
-    check("\"double\"", new Double(-1.2), new Double(1.3));
+    check("\"double\"", 1.2, 1.3);
+    check("\"double\"", -1.2, 1.3);
   }
 
   @Test
@@ -163,8 +163,8 @@ public class TestCompare {
   @Test
   public void testUnion() throws Exception {
     check("[\"string\", \"long\"]", new Utf8("a"), new Utf8("b"), false);
-    check("[\"string\", \"long\"]", new Long(1), new Long(2), false);
-    check("[\"string\", \"long\"]", new Utf8("a"), new Long(1), false);
+    check("[\"string\", \"long\"]", 1L, 2L, false);
+    check("[\"string\", \"long\"]", new Utf8("a"), 1L, false);
   }
 
   @Test
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/TestDataFileSpecific.java b/lang/java/ipc/src/test/java/org/apache/avro/TestDataFileSpecific.java
index db7e9ba..c060bde 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/TestDataFileSpecific.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/TestDataFileSpecific.java
@@ -19,7 +19,6 @@ package org.apache.avro;
 
 import java.io.File;
 import java.io.IOException;
-import java.nio.file.Files;
 
 import org.apache.avro.file.DataFileReader;
 import org.apache.avro.file.DataFileWriter;
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolGeneric.java b/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolGeneric.java
index d980da3..290a373 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolGeneric.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolGeneric.java
@@ -199,17 +199,13 @@ public class TestProtocolGeneric {
                              Schema.create(Schema.Type.STRING),
                              Schema.createUnion(new ArrayList<>()));
     protocol.getMessages().put("hello", message);
-    Transceiver t
-      = new SocketTransceiver(new InetSocketAddress(server.getPort()));
-    try {
+    try (Transceiver t = new SocketTransceiver(new InetSocketAddress(server.getPort()))) {
       GenericRequestor r = new GenericRequestor(protocol, t);
       GenericRecord params = new GenericData.Record(message.getRequest());
       params.put("extra", Boolean.TRUE);
       params.put("greeting", new Utf8("bob"));
-      Utf8 response = (Utf8)r.request("hello", params);
+      Utf8 response = (Utf8) r.request("hello", params);
       assertEquals(new Utf8("goodbye"), response);
-    } finally {
-      t.close();
     }
   }
 
@@ -237,24 +233,20 @@ public class TestProtocolGeneric {
                              record,
                              Schema.createUnion(new ArrayList<>()));
     protocol.getMessages().put("echo", message);
-    Transceiver t
-      = new SocketTransceiver(new InetSocketAddress(server.getPort()));
-    try {
+    try (Transceiver t = new SocketTransceiver(new InetSocketAddress(server.getPort()))) {
       GenericRequestor r = new GenericRequestor(protocol, t);
       GenericRecord args = new GenericData.Record(message.getRequest());
       GenericRecord rec = new GenericData.Record(record);
       rec.put("name", new Utf8("foo"));
       rec.put("kind", new GenericData.EnumSymbol
-              (PROTOCOL.getType("Kind"), "BAR"));
+        (PROTOCOL.getType("Kind"), "BAR"));
       rec.put("hash", new GenericData.Fixed
-              (PROTOCOL.getType("MD5"),
-               new byte[]{0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5}));
+        (PROTOCOL.getType("MD5"),
+          new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5}));
       rec.put("extra", Boolean.TRUE);
       args.put("record", rec);
-      GenericRecord response = (GenericRecord)r.request("echo", args);
+      GenericRecord response = (GenericRecord) r.request("echo", args);
       assertEquals(rec, response);
-    } finally {
-      t.close();
     }
   }
 
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolReflectMeta.java b/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolReflectMeta.java
index dfd34b4..e22e046 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolReflectMeta.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolReflectMeta.java
@@ -40,7 +40,7 @@ public class TestProtocolReflectMeta extends TestProtocolReflect {
     ReflectRequestor requestor = new ReflectRequestor(Simple.class, client);
     requestor.addRPCPlugin(new RPCMetaTestPlugin("key1"));
     requestor.addRPCPlugin(new RPCMetaTestPlugin("key2"));
-    proxy = ReflectRequestor.getClient(Simple.class, (ReflectRequestor)requestor);
+    proxy = ReflectRequestor.getClient(Simple.class, requestor);
   }
 
 }
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolSpecific.java b/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolSpecific.java
index 0e33627..ee270e1 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolSpecific.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolSpecific.java
@@ -93,7 +93,7 @@ public class TestProtocolSpecific {
     client = createTransceiver();
     SpecificRequestor req = new SpecificRequestor(Simple.class, client);
     addRpcPlugins(req);
-    proxy = SpecificRequestor.getClient(Simple.class, (SpecificRequestor)req);
+    proxy = SpecificRequestor.getClient(Simple.class, req);
 
     monitor = new HandshakeMonitor();
     responder.addRPCPlugin(monitor);
@@ -225,7 +225,7 @@ public class TestProtocolSpecific {
     Transceiver client = new HttpTransceiver(new URL("http://localhost:4444"));
     SpecificRequestor req = new SpecificRequestor(Simple.class, client);
     addRpcPlugins(req);
-    Simple proxy = SpecificRequestor.getClient(Simple.class, (SpecificRequestor)req);
+    Simple proxy = SpecificRequestor.getClient(Simple.class, req);
     proxy.ack();
   }
 
@@ -247,8 +247,7 @@ public class TestProtocolSpecific {
                              Schema.create(Schema.Type.STRING),
                              Schema.createUnion(new ArrayList<>()));
     protocol.getMessages().put("hello", message);
-    Transceiver t = createTransceiver();
-    try {
+    try (Transceiver t = createTransceiver()) {
       GenericRequestor r = new GenericRequestor(protocol, t);
       addRpcPlugins(r);
       GenericRecord params = new GenericData.Record(message.getRequest());
@@ -256,8 +255,6 @@ public class TestProtocolSpecific {
       params.put("greeting", "bob");
       String response = r.request("hello", params).toString();
       assertEquals("goodbye", response);
-    } finally {
-      t.close();
     }
   }
 
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java b/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java
index f13a8b2..d61d4b7 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java
@@ -486,7 +486,7 @@ public class TestSchema {
     Schema inner =
       new Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Inner\",\"fields\":[]}");
     Schema outer = Schema.createRecord("Outer", null, "space", false);
-    outer.setFields(Arrays.asList(new Field("f", inner, null, null)));
+    outer.setFields(Collections.singletonList(new Field("f", inner, null, null)));
     assertEquals(outer, new Schema.Parser().parse(outer.toString()));
   }
 
@@ -513,7 +513,7 @@ public class TestSchema {
 
   @Test
   public void testNestedNonNullNamespace1() {
-    Schema inner1 = Schema.createEnum("InnerEnum", null, "space", Arrays.asList("x"));
+    Schema inner1 = Schema.createEnum("InnerEnum", null, "space", Collections.singletonList("x"));
     Schema inner2 = new Schema.Parser().parse("{\"type\":\"record\",\"namespace\":\"space\",\"name\":"
       +"\"InnerRecord\",\"fields\":[]}");
     Schema nullOuter = Schema.createRecord("Outer", null, null, false);
@@ -930,7 +930,7 @@ public class TestSchema {
   @Test(expected=AvroRuntimeException.class)
   public void testImmutability2() {
     Schema s = enumSchema();
-    s.addProp("p1", (String)null);
+    s.addProp("p1", null);
   }
 
   private static List<String> lockedArrayList() {
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java b/lang/java/ipc/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
index eebd3db..0e228bf 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
@@ -24,7 +24,6 @@ import static org.junit.Assert.assertNotNull;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
-import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -740,7 +739,7 @@ public class TestSpecificCompiler {
 
     CompilationTask cTask = compiler.getTask(null, fileManager, null, null,
         null,
-        fileManager.getJavaFileObjects(javaFiles.toArray(new File[javaFiles.size()]))
+        fileManager.getJavaFileObjects(javaFiles.toArray(new File[0]))
     );
     assertTrue(cTask.call());
   }
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/generic/TestDeepCopy.java b/lang/java/ipc/src/test/java/org/apache/avro/generic/TestDeepCopy.java
index faf5207..f5dfbaf 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/generic/TestDeepCopy.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/generic/TestDeepCopy.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -44,7 +45,7 @@ public class TestDeepCopy {
     // Set all non-default fields in an Interop instance:
     Interop.Builder interopBuilder = Interop.newBuilder();
     interopBuilder.setArrayField(
-        Arrays.asList(new Double[] { 1.1, 1.2, 1.3, 1.4 }));
+        Arrays.asList(1.1, 1.2, 1.3, 1.4));
     interopBuilder.setBoolField(true);
     interopBuilder.setBytesField(ByteBuffer.wrap(new byte[] { 1, 2, 3, 4 }));
     interopBuilder.setDoubleField(3.14d);
@@ -65,12 +66,11 @@ public class TestDeepCopy {
     Node.Builder rootBuilder = Node.newBuilder().setLabel("/");
     Node.Builder homeBuilder = Node.newBuilder().setLabel("home");
     homeBuilder.setChildren(new ArrayList<>(0));
-    rootBuilder.setChildren(Arrays.asList(new Node[] { homeBuilder.build() }));
+    rootBuilder.setChildren(Collections.singletonList(homeBuilder.build()));
     interopBuilder.setRecordField(rootBuilder.build());
 
     interopBuilder.setStringField("Hello");
-    interopBuilder.setUnionField(Arrays.asList(new ByteBuffer[] {
-        ByteBuffer.wrap(new byte[] { 1, 2 }) }));
+    interopBuilder.setUnionField(Collections.singletonList(ByteBuffer.wrap(new byte[]{1, 2})));
 
     Interop interop = interopBuilder.build();
 
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/io/Perf.java b/lang/java/ipc/src/test/java/org/apache/avro/io/Perf.java
index df4be24..9068e8a 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/io/Perf.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/io/Perf.java
@@ -251,8 +251,7 @@ public class Perf {
 
     TestResult tr = new TestResult();
 
-    for (int k = 0; k < tests.size(); k++) {
-      Test t = tests.get(k);
+    for (Test t : tests) {
       try {
         // get everything to compile once
         t.init();
@@ -271,17 +270,16 @@ public class Perf {
 
     if (csvFormat == null) printHeader();
 
-    for (int k = 0; k < tests.size(); k++) {
-      Test t = tests.get(k);
+    for (Test t : tests) {
       // warmup JVM
       t.init();
       if (t.isReadTest() && readTests) {
-        for (int i = 0; i < t.cycles/2; i++) {
+        for (int i = 0; i < t.cycles / 2; i++) {
           t.readTest();
         }
       }
       if (t.isWriteTest() && writeTests) {
-        for (int i = 0; i < t.cycles/2; i++) {
+        for (int i = 0; i < t.cycles / 2; i++) {
           t.writeTest();
         }
       }
@@ -320,15 +318,15 @@ public class Perf {
     }
   }
 
-  private static final void printHeader() {
+  private static void printHeader() {
     String header = String.format(
         "%60s     time    M entries/sec   M bytes/sec  bytes/cycle",
         "test name");
     System.out.println(header.toString());
   }
 
-  private static final void printResult(PrintStream o, boolean[] csv,
-                                        TestResult tr, Test t, String name)
+  private static void printResult(PrintStream o, boolean[] csv,
+                                  TestResult tr, Test t, String name)
   {
     long s = tr.totalTime / 1000;
     double entries = (t.cycles * (double) t.count);
@@ -1004,8 +1002,7 @@ public class Perf {
     }
     @Override
     void writeInternal(Encoder e) throws IOException {
-      for (int i = 0; i < sourceData.length; i++) {
-        Rec r = sourceData[i];
+      for (Rec r : sourceData) {
         e.writeDouble(r.f1);
         e.writeDouble(r.f2);
         e.writeDouble(r.f3);
@@ -1100,23 +1097,22 @@ public class Perf {
       ResolvingDecoder r = (ResolvingDecoder) d;
       Field[] ff = r.readFieldOrder();
       for (int i = 0; i < count; i++) {
-        for (int j = 0; j < ff.length; j++) {
-          Field f = ff[j];
+        for (Field f : ff) {
           switch (f.pos()) {
-          case 0:
-          case 1:
-          case 2:
-            r.readDouble();
-            break;
-          case 3:
-          case 4:
-          case 5:
-            r.readInt();
-            break;
-          case 6:
-          case 7:
-            r.readString(null);
-            break;
+            case 0:
+            case 1:
+            case 2:
+              r.readDouble();
+              break;
+            case 3:
+            case 4:
+            case 5:
+              r.readInt();
+              break;
+            case 6:
+            case 7:
+              r.readString(null);
+              break;
           }
         }
       }
@@ -1142,19 +1138,18 @@ public class Perf {
       ResolvingDecoder r = (ResolvingDecoder) d;
       Field[] ff = r.readFieldOrder();
       for (int i = 0; i < count; i++) {
-        for (int j = 0; j < ff.length; j++) {
-          Field f = ff[j];
+        for (Field f : ff) {
           switch (f.pos()) {
-          case 0:
-          case 1:
-          case 3:
-            r.readDouble();
-            break;
-          case 2:
-          case 4:
-          case 5:
-            r.readInt();
-            break;
+            case 0:
+            case 1:
+            case 3:
+              r.readDouble();
+              break;
+            case 2:
+            case 4:
+            case 5:
+              r.readInt();
+              break;
           }
         }
       }
@@ -1180,19 +1175,18 @@ public class Perf {
       ResolvingDecoder r = (ResolvingDecoder) d;
       Field[] ff = r.readFieldOrder();
       for (int i = 0; i < count; i++) {
-        for (int j = 0; j < ff.length; j++) {
-          Field f = ff[j];
+        for (Field f : ff) {
           switch (f.pos()) {
-          case 0:
-          case 1:
-          case 2:
-            r.readDouble();
-            break;
-          case 3:
-          case 4:
-          case 5:
-            r.readLong();
-            break;
+            case 0:
+            case 1:
+            case 2:
+              r.readDouble();
+              break;
+            case 3:
+            case 4:
+            case 5:
+              r.readLong();
+              break;
           }
         }
       }
@@ -1242,8 +1236,7 @@ public class Perf {
     @Override
     void writeInternal(Encoder e) throws IOException {
       GenericDatumWriter<Object> writer = new GenericDatumWriter<>(schema);
-      for (int i = 0; i < sourceData.length; i++) {
-        GenericRecord rec = sourceData[i];
+      for (GenericRecord rec : sourceData) {
         writer.write(rec, e);
       }
     }
@@ -1341,18 +1334,17 @@ public class Perf {
     }
     @Override
     void writeInternal(Encoder e) throws IOException {
-      for (int i = 0; i < sourceData.length; i++) {
-        GenericRecord rec = sourceData[i];
+      for (GenericRecord rec : sourceData) {
         GenericRecord inner;
-        inner = (GenericRecord)rec.get(0);
-        e.writeDouble((Double)inner.get(0));
-        inner = (GenericRecord)rec.get(1);
-        e.writeDouble((Double)inner.get(0));
-        inner = (GenericRecord)rec.get(2);
-        e.writeDouble((Double)inner.get(0));
-        e.writeInt((Integer)rec.get(3));
-        e.writeInt((Integer)rec.get(4));
-        e.writeInt((Integer)rec.get(5));
+        inner = (GenericRecord) rec.get(0);
+        e.writeDouble((Double) inner.get(0));
+        inner = (GenericRecord) rec.get(1);
+        e.writeDouble((Double) inner.get(0));
+        inner = (GenericRecord) rec.get(2);
+        e.writeDouble((Double) inner.get(0));
+        e.writeInt((Integer) rec.get(3));
+        e.writeInt((Integer) rec.get(4));
+        e.writeInt((Integer) rec.get(5));
       }
     }
     @Override
@@ -1484,9 +1476,9 @@ public class Perf {
     }
     @Override
     void writeInternal(Encoder e) throws IOException {
-      for (int i = 0; i < sourceData.length; i++) {
+      for (Object sourceDatum : sourceData) {
         @SuppressWarnings("unchecked")
-        T rec = (T) sourceData[i];
+        T rec = (T) sourceDatum;
         writer.write(rec, e);
       }
     }
@@ -1515,7 +1507,7 @@ public class Perf {
         String[] nicknames = { randomString(r), randomString(r) };
         return FooBarSpecificRecord.newBuilder().setId(r.nextInt())
             .setName(randomString(r))
-            .setNicknames(new ArrayList<String>(Arrays.asList(nicknames)))
+            .setNicknames(new ArrayList<>(Arrays.asList(nicknames)))
             .setTypeEnum(typeEnums[r.nextInt(typeEnums.length)])
             .setRelatedids(relatedIds).build();
       } catch (Exception e) {
@@ -1559,8 +1551,8 @@ public class Perf {
 
     @Override
     protected final void writeInternal(Encoder e) throws IOException {
-      for (int i = 0; i < sourceData.length; i++) {
-        writer.write(sourceData[i], e);
+      for (T sourceDatum : sourceData) {
+        writer.write(sourceDatum, e);
       }
     }
 
@@ -1876,8 +1868,8 @@ public class Perf {
     @Override
     void writeInternal(Encoder e) throws IOException {
       GenericDatumWriter<Object> writer = new GenericDatumWriter<>(writeSchema);
-      for (int i = 0; i < sourceData.length; i++) {
-        writer.write(sourceData[i], e);
+      for (GenericRecord sourceDatum : sourceData) {
+        writer.write(sourceDatum, e);
       }
     }
 
@@ -1928,7 +1920,7 @@ public class Perf {
       for (int i = 0; i < sourceData.length; i++) {
         GenericRecord rec = new GenericData.Record(writeSchema);
         int val = r.nextInt(1000000);
-        Integer v = (val < 750000 ? new Integer(val) : null);
+        Integer v = (val < 750000 ? val : null);
         rec.put("f", v);
         sourceData[i] = rec;
       }
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslAnonymous.java b/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslAnonymous.java
index 2034e05..801f0f9 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslAnonymous.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslAnonymous.java
@@ -58,14 +58,12 @@ public class TestSaslAnonymous extends TestProtocolGeneric {
   @Test
   public void test64kRequest() throws Exception {
     SaslSocketServer s = new SaslSocketServer
-      (new ReflectResponder(ProtoInterface.class, new ProtoInterface() {
-        public byte[] test(byte[] b) { return b; }
-      }), new InetSocketAddress(0));
+      (new ReflectResponder(ProtoInterface.class, (ProtoInterface) b -> b), new InetSocketAddress(0));
     s.start();
     SaslSocketTransceiver client =
       new SaslSocketTransceiver(new InetSocketAddress(s.getPort()));
     ProtoInterface proxy =
-      (ProtoInterface)ReflectRequestor.getClient(ProtoInterface.class, client);
+      ReflectRequestor.getClient(ProtoInterface.class, client);
 
     byte[] result = proxy.test(new byte[64*1024]);
 
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/ipc/stats/TestHistogram.java b/lang/java/ipc/src/test/java/org/apache/avro/ipc/stats/TestHistogram.java
index d22d3aa..91b6f5f 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/ipc/stats/TestHistogram.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/ipc/stats/TestHistogram.java
@@ -21,11 +21,7 @@ import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.TreeSet;
+import java.util.*;
 
 import org.apache.avro.ipc.stats.Histogram.Entry;
 import org.apache.avro.ipc.stats.Histogram.Segmenter;
@@ -108,15 +104,15 @@ public class TestHistogram {
   static class SingleBucketSegmenter implements Segmenter<String, Float >{
     @Override
     public Iterator<String> getBuckets() {
-      return Arrays.asList("X").iterator();
+      return Collections.singletonList("X").iterator();
     }
 
     public List<String> getBoundaryLabels() {
-      return Arrays.asList("X");
+      return Collections.singletonList("X");
     }
 
     public List<String> getBucketLabels() {
-      return Arrays.asList("X");
+      return Collections.singletonList("X");
     }
 
     @Override
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/message/TestCustomSchemaStore.java b/lang/java/ipc/src/test/java/org/apache/avro/message/TestCustomSchemaStore.java
index 587d1c3..5de9d6a 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/message/TestCustomSchemaStore.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/message/TestCustomSchemaStore.java
@@ -62,7 +62,7 @@ public class TestCustomSchemaStore {
     // Should work
     assertEquals(nestedEvolve1.getRootName(), "RootName");
     assertEquals(nestedEvolve1.getNested().getName(), "Name");
-    assertEquals((long) nestedEvolve1.getNested().getValue(), 1);
+    assertEquals(nestedEvolve1.getNested().getValue(), 1);
   }
 
   @Test(expected = MissingSchemaException.class)
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificBuilderTree.java b/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificBuilderTree.java
index 54fc97b..9a4719d 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificBuilderTree.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificBuilderTree.java
@@ -24,7 +24,6 @@ import org.junit.Test;
 
 import java.util.ArrayList;
 import java.util.Optional;
-import java.util.function.Consumer;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificData.java b/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificData.java
index 67e29da..7aabc59 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificData.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificData.java
@@ -18,10 +18,7 @@
 package org.apache.avro.specific;
 
 import java.io.IOException;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.ArrayList;
+import java.util.*;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -123,7 +120,7 @@ public class TestSpecificData {
     FooBarSpecificRecord foo = FooBarSpecificRecord.newBuilder()
       .setId(123)
       .setName("foo")
-      .setNicknames(Arrays.asList("bar"))
+      .setNicknames(Collections.singletonList("bar"))
       .setRelatedids(Arrays.asList(1, 2, 3))
       .setTypeEnum(TypeEnum.c)
       .build();
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificDatumReader.java b/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificDatumReader.java
index f1a7420..b4c4844 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificDatumReader.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificDatumReader.java
@@ -25,6 +25,7 @@ import java.io.IOException;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 
 import org.apache.avro.FooBarSpecificRecord;
@@ -64,7 +65,7 @@ public class TestSpecificDatumReader {
     Builder newBuilder = FooBarSpecificRecord.newBuilder();
     newBuilder.setId(42);
     newBuilder.setName("foo");
-    newBuilder.setNicknames(Arrays.asList("bar"));
+    newBuilder.setNicknames(Collections.singletonList("bar"));
     newBuilder.setRelatedids(Arrays.asList(1,2,3));
     FooBarSpecificRecord specificRecord = newBuilder.build();
 
diff --git a/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificRecordBuilder.java b/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificRecordBuilder.java
index af0082f..3fe8240 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificRecordBuilder.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/specific/TestSpecificRecordBuilder.java
@@ -47,7 +47,7 @@ public class TestSpecificRecordBuilder {
     Assert.assertTrue(builder.hasName());
     Assert.assertEquals("James Gosling", builder.getName());
     Assert.assertTrue(builder.hasYearOfBirth());
-    Assert.assertEquals(1955, (int) builder.getYearOfBirth());
+    Assert.assertEquals(1955, builder.getYearOfBirth());
     Assert.assertFalse(builder.hasCountry());
     Assert.assertNull(builder.getCountry());
     Assert.assertTrue(builder.hasState());
@@ -59,7 +59,7 @@ public class TestSpecificRecordBuilder {
 
     Person person = builder.build();
     Assert.assertEquals("James Gosling", person.getName());
-    Assert.assertEquals(1955, (int) person.getYearOfBirth());
+    Assert.assertEquals(1955, person.getYearOfBirth());
     Assert.assertEquals("US", person.getCountry());  // country should default to "US"
     Assert.assertEquals("CA", person.getState());
     Assert.assertNotNull(person.getFriends());  // friends should default to an empty list
@@ -75,7 +75,7 @@ public class TestSpecificRecordBuilder {
 
     Person.Builder builderCopy = Person.newBuilder(person);
     Assert.assertEquals("James Gosling", builderCopy.getName());
-    Assert.assertEquals(1955, (int) builderCopy.getYearOfBirth());
+    Assert.assertEquals(1955, builderCopy.getYearOfBirth());
     Assert.assertEquals("US", builderCopy.getCountry());  // country should default to "US"
     Assert.assertEquals("CA", builderCopy.getState());
     Assert.assertNotNull(builderCopy.getFriends());  // friends should default to an empty list
@@ -102,13 +102,13 @@ public class TestSpecificRecordBuilder {
           .setProduct(product)
           .build())
       .build();
-    Assert.assertEquals(datetime, (long) p.getDatetime());
+    Assert.assertEquals(datetime, p.getDatetime());
     Assert.assertEquals(ProductPage.class, p.getPageContext().getClass());
     Assert.assertEquals(product, ((ProductPage)p.getPageContext()).getProduct());
 
     PageView p2 = PageView.newBuilder(p).build();
 
-    Assert.assertEquals(datetime, (long) p2.getDatetime());
+    Assert.assertEquals(datetime, p2.getDatetime());
     Assert.assertEquals(ProductPage.class, p2.getPageContext().getClass());
     Assert.assertEquals(product, ((ProductPage)p2.getPageContext()).getProduct());
 
@@ -120,7 +120,7 @@ public class TestSpecificRecordBuilder {
   public void testInterop() {
     Interop interop = Interop.newBuilder()
         .setNullField(null)
-        .setArrayField(Arrays.asList(new Double[] { 3.14159265, 6.022 }))
+        .setArrayField(Arrays.asList(3.14159265, 6.022))
         .setBoolField(true)
         .setBytesField(ByteBuffer.allocate(4).put(new byte[] { 3, 2, 1, 0 }))
         .setDoubleField(1.41421)
@@ -193,7 +193,7 @@ public class TestSpecificRecordBuilder {
   public void testBuilderPerformance() {
     int count = 1000000;
     List<Person> friends = new ArrayList<>(0);
-    List<String> languages = new ArrayList<>(Arrays.asList(new String[]{"English", "Java"}));
+    List<String> languages = new ArrayList<>(Arrays.asList("English", "Java"));
     long startTimeNanos = System.nanoTime();
     for (int ii = 0; ii < count; ii++) {
       Person.newBuilder().setName("James Gosling").setYearOfBirth(1955).setCountry("US").setState("CA").setFriends(friends).
@@ -227,7 +227,7 @@ public class TestSpecificRecordBuilder {
   public void testManualBuildPerformance() {
     int count = 1000000;
     List<Person> friends = new ArrayList<>(0);
-    List<String> languages = new ArrayList<>(Arrays.asList(new String[]{"English", "Java"}));
+    List<String> languages = new ArrayList<>(Arrays.asList("English", "Java"));
     long startTimeNanos = System.nanoTime();
     for (int ii = 0; ii < count; ii++) {
       Person person = new Person();
diff --git a/lang/java/mapred/src/main/java/org/apache/avro/hadoop/file/SortedKeyValueFile.java b/lang/java/mapred/src/main/java/org/apache/avro/hadoop/file/SortedKeyValueFile.java
index a819935..c2b9dce 100644
--- a/lang/java/mapred/src/main/java/org/apache/avro/hadoop/file/SortedKeyValueFile.java
+++ b/lang/java/mapred/src/main/java/org/apache/avro/hadoop/file/SortedKeyValueFile.java
@@ -253,9 +253,7 @@ public class SortedKeyValueFile {
       mDataFileReader.seek(indexEntry.getValue());
 
       // Scan from this position of the file until we find it or pass it.
-      Iterator<AvroKeyValue<K, V>> iter = iterator();
-      while (iter.hasNext()) {
-        AvroKeyValue<K, V> record = iter.next();
+      for (AvroKeyValue<K, V> record : this) {
         int comparison = model.compare(record.getKey(), key, mKeySchema);
         if (0 == comparison) {
           // We've found it!
@@ -307,28 +305,23 @@ public class SortedKeyValueFile {
         Configuration conf, Path path, Schema keySchema) throws IOException {
       DatumReader<GenericRecord> datumReader = model.createDatumReader(
           AvroKeyValue.getSchema(keySchema, Schema.create(Schema.Type.LONG)));
-      DataFileReader<GenericRecord> fileReader = new DataFileReader<>(
-        new FsInput(path, conf), datumReader);
-
-      NavigableMap<K, Long> index;
-      if (Schema.create(Schema.Type.STRING).equals(keySchema)) {
-        // Because Avro STRING types are mapped to the Java CharSequence class that does not
-        // mandate the implementation of Comparable, we need to specify a special
-        // CharSequence comparator if the key type is a string.  This hack only fixes the
-        // problem for primitive string types.  If, for example, you tried to use a record
-        // type as the key, any string fields inside of it would not be compared correctly
-        // against java.lang.Strings.
-        index = new TreeMap<>(new AvroCharSequenceComparator<>());
-      } else {
-        index = new TreeMap<>();
-      }
-      try {
+
+      NavigableMap<K, Long> index = new TreeMap<>();
+      try (DataFileReader<GenericRecord> fileReader = new DataFileReader<>(
+        new FsInput(path, conf), datumReader)) {
+        if (Schema.create(Schema.Type.STRING).equals(keySchema)) {
+          // Because Avro STRING types are mapped to the Java CharSequence class that does not
+          // mandate the implementation of Comparable, we need to specify a special
+          // CharSequence comparator if the key type is a string.  This hack only fixes the
+          // problem for primitive string types.  If, for example, you tried to use a record
+          // type as the key, any string fields inside of it would not be compared correctly
+          // against java.lang.Strings.
+          index = new TreeMap<>(new AvroCharSequenceComparator<>());
+        }
         for (GenericRecord genericRecord : fileReader) {
           AvroKeyValue<K, Long> indexRecord = new AvroKeyValue<>(genericRecord);
           index.put(indexRecord.getKey(), indexRecord.getValue());
         }
-      } finally {
-        fileReader.close();
       }
       return index;
     }
diff --git a/lang/java/mapred/src/main/java/org/apache/avro/hadoop/io/AvroSequenceFile.java b/lang/java/mapred/src/main/java/org/apache/avro/hadoop/io/AvroSequenceFile.java
index 38f4c7e..8341b15 100644
--- a/lang/java/mapred/src/main/java/org/apache/avro/hadoop/io/AvroSequenceFile.java
+++ b/lang/java/mapred/src/main/java/org/apache/avro/hadoop/io/AvroSequenceFile.java
@@ -723,14 +723,8 @@ public class AvroSequenceFile {
    */
   private static Metadata getMetadata(FileSystem fs, Path path, Configuration conf)
       throws IOException {
-    SequenceFile.Reader metadataReader = null;
-    try {
-      metadataReader = new SequenceFile.Reader(fs, path, conf);
+    try (SequenceFile.Reader metadataReader = new SequenceFile.Reader(fs, path, conf)) {
       return metadataReader.getMetadata();
-    } finally {
-      if (null != metadataReader) {
-        metadataReader.close();
-      }
     }
   }
 }
diff --git a/lang/java/mapred/src/main/java/org/apache/avro/hadoop/io/AvroSerialization.java b/lang/java/mapred/src/main/java/org/apache/avro/hadoop/io/AvroSerialization.java
index 4061e44..f5f7d16 100644
--- a/lang/java/mapred/src/main/java/org/apache/avro/hadoop/io/AvroSerialization.java
+++ b/lang/java/mapred/src/main/java/org/apache/avro/hadoop/io/AvroSerialization.java
@@ -126,7 +126,7 @@ public class AvroSerialization<T> extends Configured implements Serialization<Av
     if (!serializations.contains(AvroSerialization.class.getName())) {
       serializations.add(AvroSerialization.class.getName());
       conf.setStrings("io.serializations",
-          serializations.toArray(new String[serializations.size()]));
+          serializations.toArray(new String[0]));
     }
   }
 
diff --git a/lang/java/mapred/src/main/java/org/apache/avro/hadoop/util/AvroCharSequenceComparator.java b/lang/java/mapred/src/main/java/org/apache/avro/hadoop/util/AvroCharSequenceComparator.java
index 2da7111..b96b33a 100644
--- a/lang/java/mapred/src/main/java/org/apache/avro/hadoop/util/AvroCharSequenceComparator.java
+++ b/lang/java/mapred/src/main/java/org/apache/avro/hadoop/util/AvroCharSequenceComparator.java
@@ -78,7 +78,7 @@ public class AvroCharSequenceComparator<T> implements Comparator<T> {
    */
   private int compareCharacter(CharSequence o1, CharSequence o2, int index) {
     if (index < o1.length() && index < o2.length()) {
-      return Character.valueOf(o1.charAt(index)).compareTo(Character.valueOf(o2.charAt(index)));
+      return Character.compare(o1.charAt(index), o2.charAt(index));
     }
     if (index >= o1.length() && index >= o2.length()) {
       return 0;
diff --git a/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroJob.java b/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroJob.java
index 323ef35..5745e01 100644
--- a/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroJob.java
+++ b/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroJob.java
@@ -205,7 +205,7 @@ public class AvroJob {
 
   /** Return the job's data model implementation class. */
   public static Class<? extends GenericData> getDataModelClass(Configuration conf) {
-    return (Class<? extends GenericData>) conf.getClass(
+    return conf.getClass(
         CONF_DATA_MODEL, ReflectData.class, GenericData.class);
   }
 
diff --git a/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroWrapper.java b/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroWrapper.java
index 9265052..c2b4606 100644
--- a/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroWrapper.java
+++ b/lang/java/mapred/src/main/java/org/apache/avro/mapred/AvroWrapper.java
@@ -49,11 +49,8 @@ public class AvroWrapper<T> {
       return false;
     AvroWrapper that = (AvroWrapper)obj;
     if (this.datum == null) {
-      if (that.datum != null)
-        return false;
-    } else if (!datum.equals(that.datum))
-      return false;
-    return true;
+      return that.datum == null;
+    } else return datum.equals(that.datum);
   }
 
   /** Get the wrapped datum as JSON. */
diff --git a/lang/java/mapred/src/main/java/org/apache/avro/mapred/DelegatingInputFormat.java b/lang/java/mapred/src/main/java/org/apache/avro/mapred/DelegatingInputFormat.java
index 5a431a5..c63c54b 100644
--- a/lang/java/mapred/src/main/java/org/apache/avro/mapred/DelegatingInputFormat.java
+++ b/lang/java/mapred/src/main/java/org/apache/avro/mapred/DelegatingInputFormat.java
@@ -71,7 +71,7 @@ class DelegatingInputFormat<K, V> implements InputFormat<K, V> {
         schemaPaths.entrySet()) {
       Schema schema = schemaEntry.getKey();
       System.out.println(schema);
-      InputFormat format = (InputFormat) ReflectionUtils.newInstance(
+      InputFormat format = ReflectionUtils.newInstance(
          AvroInputFormat.class, conf);
       List<Path> paths = schemaEntry.getValue();
 
@@ -100,8 +100,7 @@ class DelegatingInputFormat<K, V> implements InputFormat<K, V> {
          mapperClass = (Class<? extends AvroMapper>) conf.getMapperClass();
        }
 
-       FileInputFormat.setInputPaths(confCopy, paths.toArray(new Path[paths
-           .size()]));
+       FileInputFormat.setInputPaths(confCopy, paths.toArray(new Path[0]));
 
        // Get splits for each input path and tag with InputFormat
        // and Mapper types by wrapping in a TaggedInputSplit.
@@ -113,7 +112,7 @@ class DelegatingInputFormat<K, V> implements InputFormat<K, V> {
       }
     }
 
-    return splits.toArray(new InputSplit[splits.size()]);
+    return splits.toArray(new InputSplit[0]);
   }
 
   @SuppressWarnings("unchecked")
diff --git a/lang/java/mapred/src/main/java/org/apache/avro/mapred/Pair.java b/lang/java/mapred/src/main/java/org/apache/avro/mapred/Pair.java
index 4191c6c..bc821f8 100644
--- a/lang/java/mapred/src/main/java/org/apache/avro/mapred/Pair.java
+++ b/lang/java/mapred/src/main/java/org/apache/avro/mapred/Pair.java
@@ -81,11 +81,7 @@ public class Pair<K,V>
   public static Schema getPairSchema(Schema key, Schema value) {
     Map<Schema,Schema> valueSchemas;
     synchronized (SCHEMA_CACHE) {
-      valueSchemas = SCHEMA_CACHE.get(key);
-      if (valueSchemas == null) {
-        valueSchemas = new WeakHashMap<>();
-        SCHEMA_CACHE.put(key, valueSchemas);
-      }
+      valueSchemas = SCHEMA_CACHE.computeIfAbsent(key, k -> new WeakHashMap<>());
       Schema result;
       result = valueSchemas.get(value);
       if (result == null) {
diff --git a/lang/java/mapred/src/main/java/org/apache/avro/mapred/SequenceFileReader.java b/lang/java/mapred/src/main/java/org/apache/avro/mapred/SequenceFileReader.java
index bb5d01d..e2f9d44 100644
--- a/lang/java/mapred/src/main/java/org/apache/avro/mapred/SequenceFileReader.java
+++ b/lang/java/mapred/src/main/java/org/apache/avro/mapred/SequenceFileReader.java
@@ -57,10 +57,10 @@ public class SequenceFileReader<K,V> implements FileReader<Pair<K,V>> {
   private Writable key, spareKey, value;
 
   private Converter<K> keyConverter =
-    new Converter<K>() { public K convert(Writable o) { return (K)o; } };
+    o -> (K)o;
 
   private Converter<V> valConverter =
-    new Converter<V>() { public V convert(Writable o) { return (V)o; } };
+    o -> (V)o;
 
   public SequenceFileReader(File file) throws IOException {
     this(file.toURI(), new Configuration());
@@ -200,48 +200,30 @@ public class SequenceFileReader<K,V> implements FileReader<Pair<K,V>> {
   static {
     WRITABLE_CONVERTERS.put
       (NullWritable.class,
-       new Converter<Void>() {
-         @Override public Void convert(Writable o) { return null; }
-      });
+        (Converter<Void>) o -> null);
     WRITABLE_CONVERTERS.put
       (BooleanWritable.class,
-       new Converter<Boolean>() {
-         @Override public Boolean convert(Writable o) {return ((BooleanWritable)o).get();}
-      });
+        (Converter<Boolean>) o -> ((BooleanWritable)o).get());
     WRITABLE_CONVERTERS.put
       (IntWritable.class,
-       new Converter<Integer>() {
-         @Override public Integer convert(Writable o) { return ((IntWritable)o).get(); }
-      });
+        (Converter<Integer>) o -> ((IntWritable)o).get());
     WRITABLE_CONVERTERS.put
       (LongWritable.class,
-       new Converter<Long>() {
-         @Override public Long convert(Writable o) { return ((LongWritable)o).get(); }
-      });
+        (Converter<Long>) o -> ((LongWritable)o).get());
     WRITABLE_CONVERTERS.put
       (FloatWritable.class,
-       new Converter<Float>() {
-        @Override  public Float convert(Writable o) { return ((FloatWritable)o).get(); }
-      });
+        (Converter<Float>) o -> ((FloatWritable)o).get());
     WRITABLE_CONVERTERS.put
       (DoubleWritable.class,
-       new Converter<Double>() {
-         @Override public Double convert(Writable o) { return ((DoubleWritable)o).get(); }
-      });
+        (Converter<Double>) o -> ((DoubleWritable)o).get());
     WRITABLE_CONVERTERS.put
       (BytesWritable.class,
-       new Converter<ByteBuffer>() {
-         @Override
-         public ByteBuffer convert(Writable o) {
-          BytesWritable b = (BytesWritable)o;
-          return ByteBuffer.wrap(b.getBytes(), 0, b.getLength());
-        }
-      });
+        (Converter<ByteBuffer>) o -> {
+         BytesWritable b = (BytesWritable)o;
+         return ByteBuffer.wrap(b.getBytes(), 0, b.getLength());
+       });
     WRITABLE_CONVERTERS.put
       (Text.class,
-       new Converter<String>() {
-         @Override
-         public String convert(Writable o) { return o.toString(); }
-      });
+        (Converter<String>) Object::toString);
   }
 }
diff --git a/lang/java/mapred/src/main/java/org/apache/avro/mapred/TaggedInputSplit.java b/lang/java/mapred/src/main/java/org/apache/avro/mapred/TaggedInputSplit.java
index c8eecc2..37e5ce9 100644
--- a/lang/java/mapred/src/main/java/org/apache/avro/mapred/TaggedInputSplit.java
+++ b/lang/java/mapred/src/main/java/org/apache/avro/mapred/TaggedInputSplit.java
@@ -124,7 +124,7 @@ class TaggedInputSplit implements Configurable, InputSplit {
   @Override
   public void readFields(DataInput in) throws IOException {
     inputSplitClass = (Class<? extends InputSplit>) readClass(in);
-    inputSplit = (InputSplit) ReflectionUtils
+    inputSplit = ReflectionUtils
        .newInstance(inputSplitClass, conf);
     inputSplit.readFields(in);
     inputFormatClass = (Class<? extends InputFormat>) readClass(in);
diff --git a/lang/java/mapred/src/main/java/org/apache/avro/mapred/tether/TetherOutputService.java b/lang/java/mapred/src/main/java/org/apache/avro/mapred/tether/TetherOutputService.java
index 75a810a..8ada956 100644
--- a/lang/java/mapred/src/main/java/org/apache/avro/mapred/tether/TetherOutputService.java
+++ b/lang/java/mapred/src/main/java/org/apache/avro/mapred/tether/TetherOutputService.java
@@ -92,8 +92,8 @@ class TetherOutputService implements OutputProtocol {
 
   @Override
   public synchronized void fail(String message) {
-    LOG.warn("Failing: "+message);
-    error = message.toString();
+    LOG.warn("Failing: " + message);
+    error = message;
     notify();
   }
 
diff --git a/lang/java/mapred/src/main/java/org/apache/avro/mapred/tether/TetheredProcess.java b/lang/java/mapred/src/main/java/org/apache/avro/mapred/tether/TetheredProcess.java
index a1094af..c78b37e 100644
--- a/lang/java/mapred/src/main/java/org/apache/avro/mapred/tether/TetheredProcess.java
+++ b/lang/java/mapred/src/main/java/org/apache/avro/mapred/tether/TetheredProcess.java
@@ -214,8 +214,8 @@ class TetheredProcess  {
 
     // print an info message about the command
     String imsg="";
-    for (int i=0; i<command.size();i++) {
-      imsg=command.get(i)+" ";
+    for (String s : command) {
+      imsg = s + " ";
     }
     LOG.info("TetheredProcess.startSubprocess: command: "+imsg);
     LOG.info("Tetheredprocess.startSubprocess: stdout logged to: " + stdout.toString()) ;
diff --git a/lang/java/mapred/src/main/java/org/apache/avro/mapreduce/AvroMultipleOutputs.java b/lang/java/mapred/src/main/java/org/apache/avro/mapreduce/AvroMultipleOutputs.java
index cb0b1d3..d08697c 100644
--- a/lang/java/mapred/src/main/java/org/apache/avro/mapreduce/AvroMultipleOutputs.java
+++ b/lang/java/mapred/src/main/java/org/apache/avro/mapreduce/AvroMultipleOutputs.java
@@ -486,8 +486,8 @@ public class AvroMultipleOutputs{
       //FileOutputFormat.setOutputName(taskContext, baseFileName);
       taskContext.getConfiguration().set("avro.mo.config.namedOutput",baseFileName);
       try {
-        writer = ((OutputFormat) ReflectionUtils.newInstance(
-          taskContext.getOutputFormatClass(), taskContext.getConfiguration()))
+        writer = ReflectionUtils.newInstance(
+          taskContext.getOutputFormatClass(), taskContext.getConfiguration())
           .getRecordWriter(taskContext);
       } catch (ClassNotFoundException e) {
         throw new IOException(e);
diff --git a/lang/java/mapred/src/test/java/org/apache/avro/hadoop/file/TestSortedKeyValueFile.java b/lang/java/mapred/src/test/java/org/apache/avro/hadoop/file/TestSortedKeyValueFile.java
index 4104706..310779a 100644
--- a/lang/java/mapred/src/test/java/org/apache/avro/hadoop/file/TestSortedKeyValueFile.java
+++ b/lang/java/mapred/src/test/java/org/apache/avro/hadoop/file/TestSortedKeyValueFile.java
@@ -64,16 +64,10 @@ public class TestSortedKeyValueFile {
         .withPath(new Path(mTempDir.getRoot().getPath(), "myfile"))
         .withIndexInterval(2);  // Index every other record.
 
-    SortedKeyValueFile.Writer<CharSequence, CharSequence> writer
-        = new SortedKeyValueFile.Writer<>(options);
-
-    Utf8 key = new Utf8();                        // re-use key, to test copied
-
-    try {
+    try (SortedKeyValueFile.Writer<CharSequence, CharSequence> writer = new SortedKeyValueFile.Writer<>(options)) {
+      Utf8 key = new Utf8();                        // re-use key, to test copied
       writer.append(key.set("banana"), "Banana");
       writer.append(key.set("apple"), "Apple");  // Ruh, roh!
-    } finally {
-      writer.close();
     }
   }
 
@@ -166,16 +160,11 @@ public class TestSortedKeyValueFile {
         .withPath(new Path(mTempDir.getRoot().getPath(), "myfile"))
         .withIndexInterval(2);  // Index every other record.
 
-    SortedKeyValueFile.Writer<CharSequence, CharSequence> writer
-        = new SortedKeyValueFile.Writer<>(options);
-
-    try {
+    try (SortedKeyValueFile.Writer<CharSequence, CharSequence> writer = new SortedKeyValueFile.Writer<>(options)) {
       writer.append("apple", "Apple");  // Will be indexed.
       writer.append("banana", "Banana");
       writer.append("carrot", "Carrot");  // Will be indexed.
       writer.append("durian", "Durian");
-    } finally {
-      writer.close();
     }
 
 
@@ -188,16 +177,12 @@ public class TestSortedKeyValueFile {
     File indexFile = new File(directory, SortedKeyValueFile.INDEX_FILENAME);
     DatumReader<GenericRecord> indexReader = new GenericDatumReader<>(
         AvroKeyValue.getSchema(options.getKeySchema(), Schema.create(Schema.Type.LONG)));
-    FileReader<GenericRecord> indexFileReader = DataFileReader.openReader(indexFile, indexReader);
 
-    List<AvroKeyValue<CharSequence, Long>> indexRecords
-        = new ArrayList<>();
-    try {
+    List<AvroKeyValue<CharSequence, Long>> indexRecords = new ArrayList<>();
+    try (FileReader<GenericRecord> indexFileReader = DataFileReader.openReader(indexFile, indexReader)) {
       for (GenericRecord indexRecord : indexFileReader) {
         indexRecords.add(new AvroKeyValue<>(indexRecord));
       }
-    } finally {
-      indexFileReader.close();
     }
 
     assertEquals(2, indexRecords.size());
@@ -210,31 +195,27 @@ public class TestSortedKeyValueFile {
     File dataFile = new File(directory, SortedKeyValueFile.DATA_FILENAME);
     DatumReader<GenericRecord> dataReader = new GenericDatumReader<>(
         AvroKeyValue.getSchema(options.getKeySchema(), options.getValueSchema()));
-    DataFileReader<GenericRecord> dataFileReader
-        = new DataFileReader<>(dataFile, dataReader);
 
-    try {
+    try (DataFileReader<GenericRecord> dataFileReader = new DataFileReader<>(dataFile, dataReader)) {
       dataFileReader.seek(indexRecords.get(0).getValue());
       assertTrue(dataFileReader.hasNext());
       AvroKeyValue<CharSequence, CharSequence> appleRecord
-          = new AvroKeyValue<>(dataFileReader.next());
+        = new AvroKeyValue<>(dataFileReader.next());
       assertEquals("apple", appleRecord.getKey().toString());
       assertEquals("Apple", appleRecord.getValue().toString());
 
       dataFileReader.seek(indexRecords.get(1).getValue());
       assertTrue(dataFileReader.hasNext());
       AvroKeyValue<CharSequence, CharSequence> carrotRecord
-          = new AvroKeyValue<>(dataFileReader.next());
+        = new AvroKeyValue<>(dataFileReader.next());
       assertEquals("carrot", carrotRecord.getKey().toString());
       assertEquals("Carrot", carrotRecord.getValue().toString());
 
       assertTrue(dataFileReader.hasNext());
       AvroKeyValue<CharSequence, CharSequence> durianRecord
-          = new AvroKeyValue<>(dataFileReader.next());
+        = new AvroKeyValue<>(dataFileReader.next());
       assertEquals("durian", durianRecord.getKey().toString());
       assertEquals("Durian", durianRecord.getValue().toString());
-    } finally {
-      dataFileReader.close();
     }
   }
 
@@ -248,16 +229,11 @@ public class TestSortedKeyValueFile {
         .withPath(new Path(mTempDir.getRoot().getPath(), "myfile"))
         .withIndexInterval(2);  // Index every other record.
 
-    SortedKeyValueFile.Writer<CharSequence, CharSequence> writer
-        = new SortedKeyValueFile.Writer<>(writerOptions);
-
-    try {
+    try (SortedKeyValueFile.Writer<CharSequence, CharSequence> writer = new SortedKeyValueFile.Writer<>(writerOptions)) {
       writer.append("apple", "Apple");  // Will be indexed.
       writer.append("banana", "Banana");
       writer.append("carrot", "Carrot");  // Will be indexed.
       writer.append("durian", "Durian");
-    } finally {
-      writer.close();
     }
 
     LOG.debug("Reading the file back using a reader...");
@@ -267,17 +243,12 @@ public class TestSortedKeyValueFile {
         .withConfiguration(conf)
         .withPath(new Path(mTempDir.getRoot().getPath(), "myfile"));
 
-    SortedKeyValueFile.Reader<CharSequence, CharSequence> reader
-        = new SortedKeyValueFile.Reader<>(readerOptions);
-
-    try {
+    try (SortedKeyValueFile.Reader<CharSequence, CharSequence> reader = new SortedKeyValueFile.Reader<>(readerOptions)) {
       assertEquals("Carrot", reader.get("carrot").toString());
       assertEquals("Banana", reader.get("banana").toString());
       assertNull(reader.get("a-vegetable"));
       assertNull(reader.get("beet"));
       assertNull(reader.get("zzz"));
-    } finally {
-      reader.close();
     }
   }
 
@@ -310,16 +281,11 @@ public class TestSortedKeyValueFile {
       .withDataModel(model)
       .withIndexInterval(2);
 
-    SortedKeyValueFile.Writer<Stringy,Stringy> writer
-        = new SortedKeyValueFile.Writer<>(options);
-
-    try {
+    try (SortedKeyValueFile.Writer<Stringy, Stringy> writer = new SortedKeyValueFile.Writer<>(options)) {
       writer.append(new Stringy("apple"), new Stringy("Apple"));
       writer.append(new Stringy("banana"), new Stringy("Banana"));
       writer.append(new Stringy("carrot"), new Stringy("Carrot"));
       writer.append(new Stringy("durian"), new Stringy("Durian"));
-    } finally {
-      writer.close();
     }
 
     LOG.debug("Reading the file back using a reader...");
@@ -331,17 +297,12 @@ public class TestSortedKeyValueFile {
       .withPath(new Path(mTempDir.getRoot().getPath(), "reflect"))
       .withDataModel(model);
 
-    SortedKeyValueFile.Reader<Stringy,Stringy> reader
-      = new SortedKeyValueFile.Reader<>(readerOptions);
-
-    try {
+    try (SortedKeyValueFile.Reader<Stringy, Stringy> reader = new SortedKeyValueFile.Reader<>(readerOptions)) {
       assertEquals(new Stringy("Carrot"), reader.get(new Stringy("carrot")));
       assertEquals(new Stringy("Banana"), reader.get(new Stringy("banana")));
       assertNull(reader.get(new Stringy("a-vegetable")));
       assertNull(reader.get(new Stringy("beet")));
       assertNull(reader.get(new Stringy("zzz")));
-    } finally {
-      reader.close();
     }
 
   }
diff --git a/lang/java/mapred/src/test/java/org/apache/avro/hadoop/io/TestAvroDatumConverterFactory.java b/lang/java/mapred/src/test/java/org/apache/avro/hadoop/io/TestAvroDatumConverterFactory.java
index b0a67cc..ed20c90 100644
--- a/lang/java/mapred/src/test/java/org/apache/avro/hadoop/io/TestAvroDatumConverterFactory.java
+++ b/lang/java/mapred/src/test/java/org/apache/avro/hadoop/io/TestAvroDatumConverterFactory.java
@@ -77,7 +77,7 @@ public class TestAvroDatumConverterFactory {
   public void testConvertBooleanWritable() {
     AvroDatumConverter<BooleanWritable, Boolean> converter
         = mFactory.create(BooleanWritable.class);
-    assertEquals(true, converter.convert(new BooleanWritable(true)).booleanValue());
+    assertEquals(true, converter.convert(new BooleanWritable(true)));
   }
 
   @Test
@@ -98,13 +98,13 @@ public class TestAvroDatumConverterFactory {
   @Test
   public void testConvertDoubleWritable() {
     AvroDatumConverter<DoubleWritable, Double> converter = mFactory.create(DoubleWritable.class);
-    assertEquals(2.0, converter.convert(new DoubleWritable(2.0)).doubleValue(), 0.00001);
+    assertEquals(2.0, converter.convert(new DoubleWritable(2.0)), 0.00001);
   }
 
   @Test
   public void testConvertFloatWritable() {
     AvroDatumConverter<FloatWritable, Float> converter = mFactory.create(FloatWritable.class);
-    assertEquals(2.2f, converter.convert(new FloatWritable(2.2f)).floatValue(), 0.00001);
+    assertEquals(2.2f, converter.convert(new FloatWritable(2.2f)), 0.00001);
   }
 
   @Test
diff --git a/lang/java/mapred/src/test/java/org/apache/avro/mapred/TestAvroTextSort.java b/lang/java/mapred/src/test/java/org/apache/avro/mapred/TestAvroTextSort.java
index 734d9aa..d5cced7 100644
--- a/lang/java/mapred/src/test/java/org/apache/avro/mapred/TestAvroTextSort.java
+++ b/lang/java/mapred/src/test/java/org/apache/avro/mapred/TestAvroTextSort.java
@@ -24,13 +24,10 @@ import org.apache.hadoop.mapred.FileInputFormat;
 import org.apache.hadoop.mapred.FileOutputFormat;
 import org.apache.hadoop.mapred.JobClient;
 import org.apache.hadoop.mapred.JobConf;
-import org.apache.hadoop.yarn.webapp.hamlet.Hamlet;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 
-import java.nio.file.Files;
-
 public class TestAvroTextSort {
 
   @Rule
diff --git a/lang/java/mapred/src/test/java/org/apache/avro/mapred/TestGenericJob.java b/lang/java/mapred/src/test/java/org/apache/avro/mapred/TestGenericJob.java
index 495eae4..4d624cf 100644
--- a/lang/java/mapred/src/test/java/org/apache/avro/mapred/TestGenericJob.java
+++ b/lang/java/mapred/src/test/java/org/apache/avro/mapred/TestGenericJob.java
@@ -20,9 +20,7 @@ package org.apache.avro.mapred;
 import java.io.File;
 import java.io.IOException;
 import java.io.RandomAccessFile;
-import java.nio.file.Files;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
@@ -34,7 +32,6 @@ import org.apache.avro.mapred.AvroJob;
 import org.apache.avro.mapred.AvroOutputFormat;
 import org.apache.avro.mapred.AvroWrapper;
 import org.apache.avro.mapred.Pair;
-import org.apache.hadoop.fs.FileUtil;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.io.LongWritable;
 import org.apache.hadoop.io.NullWritable;
@@ -49,7 +46,6 @@ import org.apache.hadoop.mapred.Mapper;
 import org.apache.hadoop.mapred.OutputCollector;
 import org.apache.hadoop.mapred.Reporter;
 import org.apache.hadoop.mapred.TextInputFormat;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
diff --git a/lang/java/mapred/src/test/java/org/apache/avro/mapred/tether/TestWordCountTether.java b/lang/java/mapred/src/test/java/org/apache/avro/mapred/tether/TestWordCountTether.java
index 5927734..dc7b1b4 100644
--- a/lang/java/mapred/src/test/java/org/apache/avro/mapred/tether/TestWordCountTether.java
+++ b/lang/java/mapred/src/test/java/org/apache/avro/mapred/tether/TestWordCountTether.java
@@ -24,7 +24,6 @@ import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
-import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.List;
 
diff --git a/lang/java/mapred/src/test/java/org/apache/avro/mapred/tether/TetherTask.java b/lang/java/mapred/src/test/java/org/apache/avro/mapred/tether/TetherTask.java
index 7390369..eab6166 100644
--- a/lang/java/mapred/src/test/java/org/apache/avro/mapred/tether/TetherTask.java
+++ b/lang/java/mapred/src/test/java/org/apache/avro/mapred/tether/TetherTask.java
@@ -63,8 +63,6 @@ public abstract class TetherTask<IN,MID,OUT> {
   private Collector<MID> midCollector;
   private Collector<OUT> outCollector;
 
-  private TetheredProcess.Protocol proto;
-
   private static class Buffer extends ByteArrayOutputStream {
     public ByteBuffer data() {
       return ByteBuffer.wrap(buf, 0, count);
@@ -113,10 +111,11 @@ public abstract class TetherTask<IN,MID,OUT> {
 
     protocol=protocol.trim().toLowerCase();
 
+    TetheredProcess.Protocol proto;
     if (protocol.equals("http")) {
-      proto=TetheredProcess.Protocol.HTTP;
+      proto =TetheredProcess.Protocol.HTTP;
     } else if (protocol.equals("sasl")) {
-      proto=TetheredProcess.Protocol.SASL;
+      proto =TetheredProcess.Protocol.SASL;
     } else {
       throw new RuntimeException("AVROT_TETHER_PROTOCOL="+protocol+" but this protocol is unsupported");
     }
diff --git a/lang/java/mapred/src/test/java/org/apache/avro/mapred/tether/TetherTaskRunner.java b/lang/java/mapred/src/test/java/org/apache/avro/mapred/tether/TetherTaskRunner.java
index cd69943..385b6e0 100644
--- a/lang/java/mapred/src/test/java/org/apache/avro/mapred/tether/TetherTaskRunner.java
+++ b/lang/java/mapred/src/test/java/org/apache/avro/mapred/tether/TetherTaskRunner.java
@@ -40,8 +40,6 @@ public class TetherTaskRunner implements InputProtocol {
   private Server inputServer;
   private TetherTask task;
 
-  private TetheredProcess.Protocol proto;
-
   public TetherTaskRunner(TetherTask task) throws IOException {
     this.task = task;
 
@@ -53,12 +51,13 @@ public class TetherTaskRunner implements InputProtocol {
 
     protocol=protocol.trim().toLowerCase();
 
+    TetheredProcess.Protocol proto;
     if (protocol.equals("http")) {
       LOG.info("Use HTTP protocol");
-      proto=TetheredProcess.Protocol.HTTP;
+      proto =TetheredProcess.Protocol.HTTP;
     } else if (protocol.equals("sasl")) {
       LOG.info("Use SASL protocol");
-      proto=TetheredProcess.Protocol.SASL;
+      proto =TetheredProcess.Protocol.SASL;
     } else {
       throw new RuntimeException("AVRO_TETHER_PROTOCOL="+protocol+" but this protocol is unsupported");
     }
diff --git a/lang/java/mapred/src/test/java/org/apache/avro/mapreduce/TestAvroMultipleOutputs.java b/lang/java/mapred/src/test/java/org/apache/avro/mapreduce/TestAvroMultipleOutputs.java
index c31651d..15aef0e 100644
--- a/lang/java/mapred/src/test/java/org/apache/avro/mapreduce/TestAvroMultipleOutputs.java
+++ b/lang/java/mapred/src/test/java/org/apache/avro/mapreduce/TestAvroMultipleOutputs.java
@@ -20,7 +20,6 @@
 package org.apache.avro.mapreduce;
 
 import java.io.IOException;
-import java.nio.file.Files;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -120,12 +119,12 @@ public class TestAvroMultipleOutputs {
         sum += count.get();
       }
       record.put("name", new Utf8(line.toString()));
-      record.put("count", new Integer(sum));
+      record.put("count", sum);
       mStats.datum(record);
       context.write(mStats, NullWritable.get());
       amos.write("myavro", mStats, NullWritable.get());
       record2.put("name1", new Utf8(line.toString()));
-      record2.put("count1", new Integer(sum));
+      record2.put("count1", sum);
       mStats.datum(record2);
       amos.write(mStats, NullWritable.get(), STATS_SCHEMA_2, null, "testnewwrite2");
       amos.write("myavro1", mStats);
diff --git a/lang/java/mapred/src/test/java/org/apache/avro/mapreduce/TestWordCount.java b/lang/java/mapred/src/test/java/org/apache/avro/mapreduce/TestWordCount.java
index 5873eba..70937fa 100644
--- a/lang/java/mapred/src/test/java/org/apache/avro/mapreduce/TestWordCount.java
+++ b/lang/java/mapred/src/test/java/org/apache/avro/mapreduce/TestWordCount.java
@@ -162,7 +162,7 @@ public class TestWordCount {
         sum += count.get();
       }
       record.put("name", new Utf8(line.toString()));
-      record.put("count", new Integer(sum));
+      record.put("count", sum);
       mStats.datum(record);
       context.write(mStats, NullWritable.get());
     }
@@ -507,15 +507,12 @@ public class TestWordCount {
     Path filePath = outputFiles[0].getPath();
     InputStream inputStream = filePath.getFileSystem(job.getConfiguration()).open(filePath);
     Assert.assertNotNull(inputStream);
-    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
-    try {
+    try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
       Assert.assertTrue(reader.ready());
       Assert.assertEquals("apple\t3", reader.readLine());
       Assert.assertEquals("banana\t2", reader.readLine());
       Assert.assertEquals("carrot\t1", reader.readLine());
       Assert.assertFalse(reader.ready());
-    } finally {
-      reader.close();
     }
   }
 }
diff --git a/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/AbstractAvroMojo.java b/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/AbstractAvroMojo.java
index 0d7fbee..0b0b133 100644
--- a/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/AbstractAvroMojo.java
+++ b/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/AbstractAvroMojo.java
@@ -299,7 +299,7 @@ public abstract class AbstractAvroMojo extends AbstractMojo {
   protected URLClassLoader createClassLoader() throws DependencyResolutionRequiredException, MalformedURLException {
     List<URL> urls = appendElements(project.getRuntimeClasspathElements());
     urls.addAll(appendElements(project.getTestClasspathElements()));
-    return new URLClassLoader(urls.toArray(new URL[urls.size()]),
+    return new URLClassLoader(urls.toArray(new URL[0]),
             Thread.currentThread().getContextClassLoader());
   }
 
diff --git a/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/IDLProtocolMojo.java b/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/IDLProtocolMojo.java
index 9730901..9c30122 100644
--- a/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/IDLProtocolMojo.java
+++ b/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/IDLProtocolMojo.java
@@ -101,11 +101,7 @@ public class IDLProtocolMojo extends AbstractAvroMojo {
         compiler.setOutputCharacterEncoding(project.getProperties().getProperty("project.build.sourceEncoding"));
         compiler.compileToDestination(null, outputDirectory);
       }
-    } catch (ParseException e) {
-      throw new IOException(e);
-    } catch (DependencyResolutionRequiredException drre) {
-      throw new IOException(drre);
-    } catch (ClassNotFoundException e) {
+    } catch (ParseException | ClassNotFoundException | DependencyResolutionRequiredException e) {
       throw new IOException(e);
     }
   }
diff --git a/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/InduceMojo.java b/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/InduceMojo.java
index e12183d..c786d47 100644
--- a/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/InduceMojo.java
+++ b/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/InduceMojo.java
@@ -125,7 +125,7 @@ public class InduceMojo extends AbstractMojo {
       URL[] urls = new URL[classpathElements.size()];
 
       for(int i = 0; i < classpathElements.size(); ++i) {
-        urls[i] = new File((String) classpathElements.get(i)).toURI().toURL();
+        urls[i] = new File(classpathElements.get(i)).toURI().toURL();
       }
       classLoader = new URLClassLoader(urls, getClass().getClassLoader());
     } catch (Exception e) {
diff --git a/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/ProtocolMojo.java b/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/ProtocolMojo.java
index ab78903..128423b 100644
--- a/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/ProtocolMojo.java
+++ b/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/ProtocolMojo.java
@@ -73,9 +73,7 @@ public class ProtocolMojo extends AbstractAvroMojo {
       for (String customConversion : customConversions) {
         compiler.addCustomConversion(classLoader.loadClass(customConversion));
       }
-    } catch (DependencyResolutionRequiredException e) {
-      throw new IOException(e);
-    } catch (ClassNotFoundException e) {
+    } catch (DependencyResolutionRequiredException | ClassNotFoundException e) {
       throw new IOException(e);
     }
     compiler.setOutputCharacterEncoding(project.getProperties().getProperty("project.build.sourceEncoding"));
diff --git a/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/SchemaMojo.java b/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/SchemaMojo.java
index 55eb96a..b148b1a 100644
--- a/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/SchemaMojo.java
+++ b/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/SchemaMojo.java
@@ -89,9 +89,7 @@ public class SchemaMojo extends AbstractAvroMojo {
       for (String customConversion : customConversions) {
         compiler.addCustomConversion(classLoader.loadClass(customConversion));
       }
-    } catch (ClassNotFoundException e) {
-      throw new IOException(e);
-    } catch (DependencyResolutionRequiredException e) {
+    } catch (ClassNotFoundException | DependencyResolutionRequiredException e) {
       throw new IOException(e);
     }
     compiler.setOutputCharacterEncoding(project.getProperties().getProperty("project.build.sourceEncoding"));
diff --git a/lang/java/maven-plugin/src/test/java/org/apache/avro/mojo/TestInduceMojo.java b/lang/java/maven-plugin/src/test/java/org/apache/avro/mojo/TestInduceMojo.java
index 519bf6a..3d7678c 100644
--- a/lang/java/maven-plugin/src/test/java/org/apache/avro/mojo/TestInduceMojo.java
+++ b/lang/java/maven-plugin/src/test/java/org/apache/avro/mojo/TestInduceMojo.java
@@ -58,7 +58,7 @@ public class TestInduceMojo extends AbstractMojoTestCase {
 
     File outputDir = new File(getBasedir(), "target/test-harness/schemas/org/apache/avro/entities");
     for(File file : outputDir.listFiles()) {
-      assertTrue(file.getName().indexOf(".avsc") != -1);
+      assertTrue(file.getName().contains(".avsc"));
     }
   }
 
@@ -74,7 +74,7 @@ public class TestInduceMojo extends AbstractMojoTestCase {
 
     File outputDir = new File(getBasedir(), "target/test-harness/protocol/org/apache/avro/protocols");
     for(File file : outputDir.listFiles()) {
-      assertTrue(file.getName().indexOf(".avpr") != -1);
+      assertTrue(file.getName().contains(".avpr"));
     }
   }
 
diff --git a/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java b/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java
index 92a6d2a..c29d13e 100644
--- a/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java
+++ b/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java
@@ -191,11 +191,7 @@ public class ProtobufData extends GenericData {
   }
 
   private static final ThreadLocal<Map<Descriptor,Schema>> SEEN
-    = new ThreadLocal<Map<Descriptor,Schema>>() {
-    protected Map<Descriptor,Schema> initialValue() {
-      return new IdentityHashMap<>();
-    }
-  };
+    = ThreadLocal.withInitial(IdentityHashMap::new);
 
   public Schema getSchema(Descriptor descriptor) {
     Map<Descriptor,Schema> seen = SEEN.get();
@@ -236,9 +232,9 @@ public class ProtobufData extends GenericData {
       outer = outer.substring(0, outer.lastIndexOf('.'));
       outer = toCamelCase(outer);
     }
-    String inner = "";
+    StringBuilder inner = new StringBuilder();
     while (containing != null) {
-      inner = "$" + containing.getName() + inner;
+      inner.insert(0, "$" + containing.getName());
       containing = containing.getContainingType();
     }
     return p + "." + outer + inner;
@@ -246,11 +242,11 @@ public class ProtobufData extends GenericData {
 
   private static String toCamelCase(String s){
     String[] parts = s.split("_");
-    String camelCaseString = "";
+    StringBuilder camelCaseString = new StringBuilder();
     for (String part : parts) {
-      camelCaseString = camelCaseString + cap(part);
+      camelCaseString.append(cap(part));
     }
-    return camelCaseString;
+    return camelCaseString.toString();
   }
 
   private static String cap(String s) {
diff --git a/lang/java/protobuf/src/test/java/org/apache/avro/protobuf/Test.java b/lang/java/protobuf/src/test/java/org/apache/avro/protobuf/Test.java
index a244bc6..f89faa8 100644
--- a/lang/java/protobuf/src/test/java/org/apache/avro/protobuf/Test.java
+++ b/lang/java/protobuf/src/test/java/org/apache/avro/protobuf/Test.java
@@ -3,6 +3,8 @@
 
 package org.apache.avro.protobuf;
 
+import com.google.protobuf.CodedOutputStream;
+
 public final class Test {
   private Test() {}
   public static void registerAllExtensions(
@@ -62,11 +64,7 @@ public final class Test {
     }
     private static com.google.protobuf.Internal.EnumLiteMap<A>
         internalValueMap =
-          new com.google.protobuf.Internal.EnumLiteMap<A>() {
-            public A findValueByNumber(int number) {
-              return A.valueOf(number);
-            }
-          };
+      A::valueOf;
 
     public final com.google.protobuf.Descriptors.EnumValueDescriptor
         getValueDescriptor() {
@@ -76,7 +74,7 @@ public final class Test {
         getDescriptorForType() {
       return getDescriptor();
     }
-    public static final com.google.protobuf.Descriptors.EnumDescriptor
+    public static com.google.protobuf.Descriptors.EnumDescriptor
         getDescriptor() {
       return org.apache.avro.protobuf.Test.getDescriptor().getEnumTypes().get(0);
     }
@@ -509,7 +507,7 @@ public final class Test {
             }
             case 136: {
               if (!((mutable_bitField0_ & 0x00010000) == 0x00010000)) {
-                intArray_ = new java.util.ArrayList<java.lang.Integer>();
+                intArray_ = new java.util.ArrayList<>();
                 mutable_bitField0_ |= 0x00010000;
               }
               intArray_.add(input.readInt32());
@@ -519,7 +517,7 @@ public final class Test {
               int length = input.readRawVarint32();
               int limit = input.pushLimit(length);
               if (!((mutable_bitField0_ & 0x00010000) == 0x00010000) && input.getBytesUntilLimit() > 0) {
-                intArray_ = new java.util.ArrayList<java.lang.Integer>();
+                intArray_ = new java.util.ArrayList<>();
                 mutable_bitField0_ |= 0x00010000;
               }
               while (input.getBytesUntilLimit() > 0) {
@@ -548,7 +546,7 @@ public final class Test {
                 unknownFields.mergeVarintField(19, rawValue);
               } else {
                 if (!((mutable_bitField0_ & 0x00040000) == 0x00040000)) {
-                  syms_ = new java.util.ArrayList<org.apache.avro.protobuf.Test.A>();
+                  syms_ = new java.util.ArrayList<>();
                   mutable_bitField0_ |= 0x00040000;
                 }
                 syms_.add(value);
@@ -565,7 +563,7 @@ public final class Test {
                   unknownFields.mergeVarintField(19, rawValue);
                 } else {
                   if (!((mutable_bitField0_ & 0x00040000) == 0x00040000)) {
-                    syms_ = new java.util.ArrayList<org.apache.avro.protobuf.Test.A>();
+                    syms_ = new java.util.ArrayList<>();
                     mutable_bitField0_ |= 0x00040000;
                   }
                   syms_.add(value);
@@ -576,7 +574,7 @@ public final class Test {
             }
             case 162: {
               if (!((mutable_bitField0_ & 0x00020000) == 0x00020000)) {
-                fooArray_ = new java.util.ArrayList<org.apache.avro.protobuf.Test.Foo>();
+                fooArray_ = new java.util.ArrayList<>();
                 mutable_bitField0_ |= 0x00020000;
               }
               fooArray_.add(input.readMessage(org.apache.avro.protobuf.Test.Foo.PARSER, extensionRegistry));
@@ -603,7 +601,7 @@ public final class Test {
         makeExtensionsImmutable();
       }
     }
-    public static final com.google.protobuf.Descriptors.Descriptor
+    public static com.google.protobuf.Descriptors.Descriptor
         getDescriptor() {
       return org.apache.avro.protobuf.Test.internal_static_org_apache_avro_protobuf_Foo_descriptor;
     }
@@ -1147,17 +1145,17 @@ public final class Test {
       if (((bitField0_ & 0x00008000) == 0x00008000)) {
         output.writeEnum(16, enum_.getNumber());
       }
-      for (int i = 0; i < intArray_.size(); i++) {
-        output.writeInt32(17, intArray_.get(i));
+      for (Integer integer : intArray_) {
+        output.writeInt32(17, integer);
       }
       if (((bitField0_ & 0x00010000) == 0x00010000)) {
         output.writeMessage(18, foo_);
       }
-      for (int i = 0; i < syms_.size(); i++) {
-        output.writeEnum(19, syms_.get(i).getNumber());
+      for (A a : syms_) {
+        output.writeEnum(19, a.getNumber());
       }
-      for (int i = 0; i < fooArray_.size(); i++) {
-        output.writeMessage(20, fooArray_.get(i));
+      for (Foo foo : fooArray_) {
+        output.writeMessage(20, foo);
       }
       getUnknownFields().writeTo(output);
     }
@@ -1234,9 +1232,9 @@ public final class Test {
       }
       {
         int dataSize = 0;
-        for (int i = 0; i < intArray_.size(); i++) {
-          dataSize += com.google.protobuf.CodedOutputStream
-            .computeInt32SizeNoTag(intArray_.get(i));
+        for (Integer integer : intArray_) {
+          dataSize += CodedOutputStream
+            .computeInt32SizeNoTag(integer);
         }
         size += dataSize;
         size += 2 * getIntArrayList().size();
@@ -1247,16 +1245,16 @@ public final class Test {
       }
       {
         int dataSize = 0;
-        for (int i = 0; i < syms_.size(); i++) {
-          dataSize += com.google.protobuf.CodedOutputStream
-            .computeEnumSizeNoTag(syms_.get(i).getNumber());
+        for (A a : syms_) {
+          dataSize += CodedOutputStream
+            .computeEnumSizeNoTag(a.getNumber());
         }
         size += dataSize;
         size += 2 * syms_.size();
       }
-      for (int i = 0; i < fooArray_.size(); i++) {
-        size += com.google.protobuf.CodedOutputStream
-          .computeMessageSize(20, fooArray_.get(i));
+      for (Foo foo : fooArray_) {
+        size += CodedOutputStream
+          .computeMessageSize(20, foo);
       }
       size += getUnknownFields().getSerializedSize();
       memoizedSerializedSize = size;
@@ -1342,7 +1340,7 @@ public final class Test {
     public static final class Builder extends
         com.google.protobuf.GeneratedMessage.Builder<Builder>
        implements org.apache.avro.protobuf.Test.FooOrBuilder {
-      public static final com.google.protobuf.Descriptors.Descriptor
+      public static com.google.protobuf.Descriptors.Descriptor
           getDescriptor() {
         return org.apache.avro.protobuf.Test.internal_static_org_apache_avro_protobuf_Foo_descriptor;
       }
@@ -1674,10 +1672,7 @@ public final class Test {
           }
         }
         if (hasFoo()) {
-          if (!getFoo().isInitialized()) {
-
-            return false;
-          }
+          return getFoo().isInitialized();
         }
         return true;
       }
@@ -2325,7 +2320,7 @@ public final class Test {
       private java.util.List<java.lang.Integer> intArray_ = java.util.Collections.emptyList();
       private void ensureIntArrayIsMutable() {
         if (!((bitField0_ & 0x00010000) == 0x00010000)) {
-          intArray_ = new java.util.ArrayList<java.lang.Integer>(intArray_);
+          intArray_ = new java.util.ArrayList<>(intArray_);
           bitField0_ |= 0x00010000;
          }
       }
@@ -2420,7 +2415,7 @@ public final class Test {
         java.util.Collections.emptyList();
       private void ensureFooArrayIsMutable() {
         if (!((bitField0_ & 0x00020000) == 0x00020000)) {
-          fooArray_ = new java.util.ArrayList<org.apache.avro.protobuf.Test.Foo>(fooArray_);
+          fooArray_ = new java.util.ArrayList<>(fooArray_);
           bitField0_ |= 0x00020000;
          }
       }
@@ -2644,12 +2639,11 @@ public final class Test {
           org.apache.avro.protobuf.Test.Foo, org.apache.avro.protobuf.Test.Foo.Builder, org.apache.avro.protobuf.Test.FooOrBuilder>
           getFooArrayFieldBuilder() {
         if (fooArrayBuilder_ == null) {
-          fooArrayBuilder_ = new com.google.protobuf.RepeatedFieldBuilder<
-              org.apache.avro.protobuf.Test.Foo, org.apache.avro.protobuf.Test.Foo.Builder, org.apache.avro.protobuf.Test.FooOrBuilder>(
-                  fooArray_,
-                  ((bitField0_ & 0x00020000) == 0x00020000),
-                  getParentForChildren(),
-                  isClean());
+          fooArrayBuilder_ = new com.google.protobuf.RepeatedFieldBuilder<>(
+            fooArray_,
+            ((bitField0_ & 0x00020000) == 0x00020000),
+            getParentForChildren(),
+            isClean());
           fooArray_ = null;
         }
         return fooArrayBuilder_;
@@ -2660,7 +2654,7 @@ public final class Test {
         java.util.Collections.emptyList();
       private void ensureSymsIsMutable() {
         if (!((bitField0_ & 0x00040000) == 0x00040000)) {
-          syms_ = new java.util.ArrayList<org.apache.avro.protobuf.Test.A>(syms_);
+          syms_ = new java.util.ArrayList<>(syms_);
           bitField0_ |= 0x00040000;
         }
       }
@@ -2870,11 +2864,10 @@ public final class Test {
           org.apache.avro.protobuf.Test.Foo, org.apache.avro.protobuf.Test.Foo.Builder, org.apache.avro.protobuf.Test.FooOrBuilder>
           getFooFieldBuilder() {
         if (fooBuilder_ == null) {
-          fooBuilder_ = new com.google.protobuf.SingleFieldBuilder<
-              org.apache.avro.protobuf.Test.Foo, org.apache.avro.protobuf.Test.Foo.Builder, org.apache.avro.protobuf.Test.FooOrBuilder>(
-                  foo_,
-                  getParentForChildren(),
-                  isClean());
+          fooBuilder_ = new com.google.protobuf.SingleFieldBuilder<>(
+            foo_,
+            getParentForChildren(),
+            isClean());
           foo_ = null;
         }
         return fooBuilder_;
@@ -2960,7 +2953,7 @@ public final class Test {
         makeExtensionsImmutable();
       }
     }
-    public static final com.google.protobuf.Descriptors.Descriptor
+    public static com.google.protobuf.Descriptors.Descriptor
         getDescriptor() {
       return org.apache.avro.protobuf.Test.internal_static_org_apache_avro_protobuf_M_descriptor;
     }
@@ -3019,11 +3012,7 @@ public final class Test {
       }
       private static com.google.protobuf.Internal.EnumLiteMap<N>
           internalValueMap =
-            new com.google.protobuf.Internal.EnumLiteMap<N>() {
-              public N findValueByNumber(int number) {
-                return N.valueOf(number);
-              }
-            };
+        N::valueOf;
 
       public final com.google.protobuf.Descriptors.EnumValueDescriptor
           getValueDescriptor() {
@@ -3033,7 +3022,7 @@ public final class Test {
           getDescriptorForType() {
         return getDescriptor();
       }
-      public static final com.google.protobuf.Descriptors.EnumDescriptor
+      public static com.google.protobuf.Descriptors.EnumDescriptor
           getDescriptor() {
         return org.apache.avro.protobuf.Test.M.getDescriptor().getEnumTypes().get(0);
       }
@@ -3171,7 +3160,7 @@ public final class Test {
     public static final class Builder extends
         com.google.protobuf.GeneratedMessage.Builder<Builder>
        implements org.apache.avro.protobuf.Test.MOrBuilder {
-      public static final com.google.protobuf.Descriptors.Descriptor
+      public static com.google.protobuf.Descriptors.Descriptor
           getDescriptor() {
         return org.apache.avro.protobuf.Test.internal_static_org_apache_avro_protobuf_M_descriptor;
       }
diff --git a/lang/java/thrift/src/test/java/org/apache/avro/thrift/test/Error.java b/lang/java/thrift/src/test/java/org/apache/avro/thrift/test/Error.java
index f5bf35a..d50e187 100644
--- a/lang/java/thrift/src/test/java/org/apache/avro/thrift/test/Error.java
+++ b/lang/java/thrift/src/test/java/org/apache/avro/thrift/test/Error.java
@@ -212,8 +212,7 @@ public class Error extends TException implements org.apache.thrift.TBase<Error,
     if (this_present_message || that_present_message) {
       if (!(this_present_message && that_present_message))
         return false;
-      if (!this.message.equals(that.message))
-        return false;
+      return this.message.equals(that.message);
     }
 
     return true;
@@ -232,7 +231,7 @@ public class Error extends TException implements org.apache.thrift.TBase<Error,
 
     int lastComparison = 0;
 
-    lastComparison = Boolean.valueOf(isSetMessage()).compareTo(other.isSetMessage());
+    lastComparison = Boolean.compare(isSetMessage(), other.isSetMessage());
     if (lastComparison != 0) {
       return lastComparison;
     }
diff --git a/lang/java/thrift/src/test/java/org/apache/avro/thrift/test/Foo.java b/lang/java/thrift/src/test/java/org/apache/avro/thrift/test/Foo.java
index e36b753..c0a046e 100644
--- a/lang/java/thrift/src/test/java/org/apache/avro/thrift/test/Foo.java
+++ b/lang/java/thrift/src/test/java/org/apache/avro/thrift/test/Foo.java
@@ -86,7 +86,6 @@ public class Foo {
     {
       ping_result result = new ping_result();
       receiveBase(result, "ping");
-      return;
     }
 
     @Override
@@ -625,10 +624,7 @@ public class Foo {
     }
 
     public boolean equals(ping_args that) {
-      if (that == null)
-        return false;
-
-      return true;
+      return that != null;
     }
 
     @Override
@@ -661,11 +657,9 @@ public class Foo {
 
     @Override
     public String toString() {
-      StringBuilder sb = new StringBuilder("ping_args(");
       boolean first = true;
 
-      sb.append(")");
-      return sb.toString();
+      return "ping_args(" + ")";
     }
 
     public void validate() throws org.apache.thrift.TException {
@@ -869,10 +863,7 @@ public class Foo {
     }
 
     public boolean equals(ping_result that) {
-      if (that == null)
-        return false;
-
-      return true;
+      return that != null;
     }
 
     @Override
@@ -905,11 +896,9 @@ public class Foo {
 
     @Override
     public String toString() {
-      StringBuilder sb = new StringBuilder("ping_result(");
       boolean first = true;
 
-      sb.append(")");
-      return sb.toString();
+      return "ping_result(" + ")";
     }
 
     public void validate() throws org.apache.thrift.TException {
@@ -1185,10 +1174,10 @@ public class Foo {
     public Object getFieldValue(_Fields field) {
       switch (field) {
       case NUM1:
-        return Integer.valueOf(getNum1());
+        return getNum1();
 
       case NUM2:
-        return Integer.valueOf(getNum2());
+        return getNum2();
 
       }
       throw new IllegalStateException();
@@ -1236,8 +1225,7 @@ public class Foo {
       if (this_present_num2 || that_present_num2) {
         if (!(this_present_num2 && that_present_num2))
           return false;
-        if (this.num2 != that.num2)
-          return false;
+        return this.num2 == that.num2;
       }
 
       return true;
@@ -1256,7 +1244,7 @@ public class Foo {
 
       int lastComparison = 0;
 
-      lastComparison = Boolean.valueOf(isSetNum1()).compareTo(other.isSetNum1());
+      lastComparison = Boolean.compare(isSetNum1(), other.isSetNum1());
       if (lastComparison != 0) {
         return lastComparison;
       }
@@ -1266,7 +1254,7 @@ public class Foo {
           return lastComparison;
         }
       }
-      lastComparison = Boolean.valueOf(isSetNum2()).compareTo(other.isSetNum2());
+      lastComparison = Boolean.compare(isSetNum2(), other.isSetNum2());
       if (lastComparison != 0) {
         return lastComparison;
       }
@@ -1583,7 +1571,7 @@ public class Foo {
     public Object getFieldValue(_Fields field) {
       switch (field) {
       case SUCCESS:
-        return Integer.valueOf(getSuccess());
+        return getSuccess();
 
       }
       throw new IllegalStateException();
@@ -1620,8 +1608,7 @@ public class Foo {
       if (this_present_success || that_present_success) {
         if (!(this_present_success && that_present_success))
           return false;
-        if (this.success != that.success)
-          return false;
+        return this.success == that.success;
       }
 
       return true;
@@ -1640,7 +1627,7 @@ public class Foo {
 
       int lastComparison = 0;
 
-      lastComparison = Boolean.valueOf(isSetSuccess()).compareTo(other.isSetSuccess());
+      lastComparison = Boolean.compare(isSetSuccess(), other.isSetSuccess());
       if (lastComparison != 0) {
         return lastComparison;
       }
@@ -1906,10 +1893,7 @@ public class Foo {
     }
 
     public boolean equals(zip_args that) {
-      if (that == null)
-        return false;
-
-      return true;
+      return that != null;
     }
 
     @Override
@@ -1942,11 +1926,9 @@ public class Foo {
 
     @Override
     public String toString() {
-      StringBuilder sb = new StringBuilder("zip_args(");
       boolean first = true;
 
-      sb.append(")");
-      return sb.toString();
+      return "zip_args(" + ")";
     }
 
     public void validate() throws org.apache.thrift.TException {
diff --git a/lang/java/thrift/src/test/java/org/apache/avro/thrift/test/Nested.java b/lang/java/thrift/src/test/java/org/apache/avro/thrift/test/Nested.java
index 6b0d805..4397c25 100644
--- a/lang/java/thrift/src/test/java/org/apache/avro/thrift/test/Nested.java
+++ b/lang/java/thrift/src/test/java/org/apache/avro/thrift/test/Nested.java
@@ -176,7 +176,7 @@ public class Nested implements org.apache.thrift.TBase<Nested, Nested._Fields>,
   public Object getFieldValue(_Fields field) {
     switch (field) {
     case X:
-      return Integer.valueOf(getX());
+      return getX();
 
     }
     throw new IllegalStateException();
@@ -214,8 +214,7 @@ public class Nested implements org.apache.thrift.TBase<Nested, Nested._Fields>,
     if (this_present_x || that_present_x) {
       if (!(this_present_x && that_present_x))
         return false;
-      if (this.x != that.x)
-        return false;
+      return this.x == that.x;
     }
 
     return true;
@@ -234,7 +233,7 @@ public class Nested implements org.apache.thrift.TBase<Nested, Nested._Fields>,
 
     int lastComparison = 0;
 
-    lastComparison = Boolean.valueOf(isSetX()).compareTo(other.isSetX());
+    lastComparison = Boolean.compare(isSetX(), other.isSetX());
     if (lastComparison != 0) {
       return lastComparison;
     }
diff --git a/lang/java/thrift/src/test/java/org/apache/avro/thrift/test/Test.java b/lang/java/thrift/src/test/java/org/apache/avro/thrift/test/Test.java
index a6b736e..d9b40d4 100644
--- a/lang/java/thrift/src/test/java/org/apache/avro/thrift/test/Test.java
+++ b/lang/java/thrift/src/test/java/org/apache/avro/thrift/test/Test.java
@@ -554,7 +554,7 @@ public class Test implements org.apache.thrift.TBase<Test, Test._Fields>, java.i
   }
 
   public void setBinaryField(byte[] binaryField) {
-    setBinaryField(binaryField == null ? (ByteBuffer)null : ByteBuffer.wrap(binaryField));
+    setBinaryField(binaryField == null ? null : ByteBuffer.wrap(binaryField));
   }
 
   public void setBinaryField(ByteBuffer binaryField) {
@@ -901,28 +901,28 @@ public class Test implements org.apache.thrift.TBase<Test, Test._Fields>, java.i
   public Object getFieldValue(_Fields field) {
     switch (field) {
     case BOOL_FIELD:
-      return Boolean.valueOf(isBoolField());
+      return isBoolField();
 
     case BYTE_FIELD:
-      return Byte.valueOf(getByteField());
+      return getByteField();
 
     case BYTE_OPTIONAL_FIELD:
-      return Byte.valueOf(getByteOptionalField());
+      return getByteOptionalField();
 
     case I16_FIELD:
-      return Short.valueOf(getI16Field());
+      return getI16Field();
 
     case I16_OPTIONAL_FIELD:
-      return Short.valueOf(getI16OptionalField());
+      return getI16OptionalField();
 
     case I32_FIELD:
-      return Integer.valueOf(getI32Field());
+      return getI32Field();
 
     case I64_FIELD:
-      return Long.valueOf(getI64Field());
+      return getI64Field();
 
     case DOUBLE_FIELD:
-      return Double.valueOf(getDoubleField());
+      return getDoubleField();
 
     case STRING_FIELD:
       return getStringField();
@@ -1149,8 +1149,7 @@ public class Test implements org.apache.thrift.TBase<Test, Test._Fields>, java.i
     if (this_present_fooOrBar || that_present_fooOrBar) {
       if (!(this_present_fooOrBar && that_present_fooOrBar))
         return false;
-      if (!this.fooOrBar.equals(that.fooOrBar))
-        return false;
+      return this.fooOrBar.equals(that.fooOrBar);
     }
 
     return true;
@@ -1169,7 +1168,7 @@ public class Test implements org.apache.thrift.TBase<Test, Test._Fields>, java.i
 
     int lastComparison = 0;
 
-    lastComparison = Boolean.valueOf(isSetBoolField()).compareTo(other.isSetBoolField());
+    lastComparison = Boolean.compare(isSetBoolField(), other.isSetBoolField());
     if (lastComparison != 0) {
       return lastComparison;
     }
@@ -1179,7 +1178,7 @@ public class Test implements org.apache.thrift.TBase<Test, Test._Fields>, java.i
         return lastComparison;
       }
     }
-    lastComparison = Boolean.valueOf(isSetByteField()).compareTo(other.isSetByteField());
+    lastComparison = Boolean.compare(isSetByteField(), other.isSetByteField());
     if (lastComparison != 0) {
       return lastComparison;
     }
@@ -1189,7 +1188,7 @@ public class Test implements org.apache.thrift.TBase<Test, Test._Fields>, java.i
         return lastComparison;
       }
     }
-    lastComparison = Boolean.valueOf(isSetByteOptionalField()).compareTo(other.isSetByteOptionalField());
+    lastComparison = Boolean.compare(isSetByteOptionalField(), other.isSetByteOptionalField());
     if (lastComparison != 0) {
       return lastComparison;
     }
@@ -1199,7 +1198,7 @@ public class Test implements org.apache.thrift.TBase<Test, Test._Fields>, java.i
         return lastComparison;
       }
     }
-    lastComparison = Boolean.valueOf(isSetI16Field()).compareTo(other.isSetI16Field());
+    lastComparison = Boolean.compare(isSetI16Field(), other.isSetI16Field());
     if (lastComparison != 0) {
       return lastComparison;
     }
@@ -1209,7 +1208,7 @@ public class Test implements org.apache.thrift.TBase<Test, Test._Fields>, java.i
         return lastComparison;
       }
     }
-    lastComparison = Boolean.valueOf(isSetI16OptionalField()).compareTo(other.isSetI16OptionalField());
+    lastComparison = Boolean.compare(isSetI16OptionalField(), other.isSetI16OptionalField());
     if (lastComparison != 0) {
       return lastComparison;
     }
@@ -1219,7 +1218,7 @@ public class Test implements org.apache.thrift.TBase<Test, Test._Fields>, java.i
         return lastComparison;
       }
     }
-    lastComparison = Boolean.valueOf(isSetI32Field()).compareTo(other.isSetI32Field());
+    lastComparison = Boolean.compare(isSetI32Field(), other.isSetI32Field());
     if (lastComparison != 0) {
       return lastComparison;
     }
@@ -1229,7 +1228,7 @@ public class Test implements org.apache.thrift.TBase<Test, Test._Fields>, java.i
         return lastComparison;
       }
     }
-    lastComparison = Boolean.valueOf(isSetI64Field()).compareTo(other.isSetI64Field());
+    lastComparison = Boolean.compare(isSetI64Field(), other.isSetI64Field());
     if (lastComparison != 0) {
       return lastComparison;
     }
@@ -1239,7 +1238,7 @@ public class Test implements org.apache.thrift.TBase<Test, Test._Fields>, java.i
         return lastComparison;
       }
     }
-    lastComparison = Boolean.valueOf(isSetDoubleField()).compareTo(other.isSetDoubleField());
+    lastComparison = Boolean.compare(isSetDoubleField(), other.isSetDoubleField());
     if (lastComparison != 0) {
       return lastComparison;
     }
@@ -1249,7 +1248,7 @@ public class Test implements org.apache.thrift.TBase<Test, Test._Fields>, java.i
         return lastComparison;
       }
     }
-    lastComparison = Boolean.valueOf(isSetStringField()).compareTo(other.isSetStringField());
+    lastComparison = Boolean.compare(isSetStringField(), other.isSetStringField());
     if (lastComparison != 0) {
       return lastComparison;
     }
@@ -1259,7 +1258,7 @@ public class Test implements org.apache.thrift.TBase<Test, Test._Fields>, java.i
         return lastComparison;
       }
     }
-    lastComparison = Boolean.valueOf(isSetBinaryField()).compareTo(other.isSetBinaryField());
+    lastComparison = Boolean.compare(isSetBinaryField(), other.isSetBinaryField());
     if (lastComparison != 0) {
       return lastComparison;
     }
@@ -1269,7 +1268,7 @@ public class Test implements org.apache.thrift.TBase<Test, Test._Fields>, java.i
         return lastComparison;
       }
     }
-    lastComparison = Boolean.valueOf(isSetMapField()).compareTo(other.isSetMapField());
+    lastComparison = Boolean.compare(isSetMapField(), other.isSetMapField());
     if (lastComparison != 0) {
       return lastComparison;
     }
@@ -1279,7 +1278,7 @@ public class Test implements org.apache.thrift.TBase<Test, Test._Fields>, java.i
         return lastComparison;
       }
     }
-    lastComparison = Boolean.valueOf(isSetListField()).compareTo(other.isSetListField());
+    lastComparison = Boolean.compare(isSetListField(), other.isSetListField());
     if (lastComparison != 0) {
       return lastComparison;
     }
@@ -1289,7 +1288,7 @@ public class Test implements org.apache.thrift.TBase<Test, Test._Fields>, java.i
         return lastComparison;
       }
     }
-    lastComparison = Boolean.valueOf(isSetSetField()).compareTo(other.isSetSetField());
+    lastComparison = Boolean.compare(isSetSetField(), other.isSetSetField());
     if (lastComparison != 0) {
       return lastComparison;
     }
@@ -1299,7 +1298,7 @@ public class Test implements org.apache.thrift.TBase<Test, Test._Fields>, java.i
         return lastComparison;
       }
     }
-    lastComparison = Boolean.valueOf(isSetEnumField()).compareTo(other.isSetEnumField());
+    lastComparison = Boolean.compare(isSetEnumField(), other.isSetEnumField());
     if (lastComparison != 0) {
       return lastComparison;
     }
@@ -1309,7 +1308,7 @@ public class Test implements org.apache.thrift.TBase<Test, Test._Fields>, java.i
         return lastComparison;
       }
     }
-    lastComparison = Boolean.valueOf(isSetStructField()).compareTo(other.isSetStructField());
+    lastComparison = Boolean.compare(isSetStructField(), other.isSetStructField());
     if (lastComparison != 0) {
       return lastComparison;
     }
@@ -1319,7 +1318,7 @@ public class Test implements org.apache.thrift.TBase<Test, Test._Fields>, java.i
         return lastComparison;
       }
     }
-    lastComparison = Boolean.valueOf(isSetFooOrBar()).compareTo(other.isSetFooOrBar());
+    lastComparison = Boolean.compare(isSetFooOrBar(), other.isSetFooOrBar());
     if (lastComparison != 0) {
       return lastComparison;
     }
diff --git a/lang/java/tools/src/main/java/org/apache/avro/tool/DataFileReadTool.java b/lang/java/tools/src/main/java/org/apache/avro/tool/DataFileReadTool.java
index ad63f21..8e7523c 100644
--- a/lang/java/tools/src/main/java/org/apache/avro/tool/DataFileReadTool.java
+++ b/lang/java/tools/src/main/java/org/apache/avro/tool/DataFileReadTool.java
@@ -61,7 +61,7 @@ public class DataFileReadTool implements Tool {
 
     OptionSet optionSet = optionParser.parse(args.toArray(new String[0]));
     Boolean pretty = optionSet.has(prettyOption);
-    List<String> nargs = new ArrayList<String>((List<String>)optionSet.nonOptionArguments());
+    List<String> nargs = new ArrayList<>((List<String>) optionSet.nonOptionArguments());
 
     long headCount = getHeadCount(optionSet, headOption, nargs);
 
@@ -75,20 +75,17 @@ public class DataFileReadTool implements Tool {
     BufferedInputStream inStream = Util.fileOrStdin(nargs.get(0), stdin);
 
     GenericDatumReader<Object> reader = new GenericDatumReader<>();
-    DataFileStream<Object> streamReader = new DataFileStream<>(inStream, reader);
-    try {
+    try (DataFileStream<Object> streamReader = new DataFileStream<>(inStream, reader)) {
       Schema schema = streamReader.getSchema();
       DatumWriter<Object> writer = new GenericDatumWriter<>(schema);
       JsonEncoder encoder = EncoderFactory.get().jsonEncoder(schema, out, pretty);
-      for(long recordCount = 0; streamReader.hasNext() && recordCount < headCount; recordCount++) {
+      for (long recordCount = 0; streamReader.hasNext() && recordCount < headCount; recordCount++) {
         Object datum = streamReader.next();
         writer.write(datum, encoder);
       }
       encoder.flush();
       out.println();
       out.flush();
-    } finally {
-      streamReader.close();
     }
     return 0;
   }
diff --git a/lang/java/tools/src/main/java/org/apache/avro/tool/DataFileRepairTool.java b/lang/java/tools/src/main/java/org/apache/avro/tool/DataFileRepairTool.java
index d3afbc9..ac23fe9 100644
--- a/lang/java/tools/src/main/java/org/apache/avro/tool/DataFileRepairTool.java
+++ b/lang/java/tools/src/main/java/org/apache/avro/tool/DataFileRepairTool.java
@@ -126,9 +126,8 @@ public class DataFileRepairTool implements Tool {
     }
     out.println("Recovering file: " + input);
     GenericDatumReader<Object> reader = new GenericDatumReader<>();
-    DataFileReader<Object> fileReader = new DataFileReader<>(infile,
-        reader);
-    try {
+    try (DataFileReader<Object> fileReader = new DataFileReader<>(infile,
+      reader)) {
       Schema schema = fileReader.getSchema();
       String codecStr = fileReader.getMetaString(DataFileConstants.CODEC);
       CodecFactory codecFactory = CodecFactory.fromString("" + codecStr);
@@ -146,7 +145,7 @@ public class DataFileRepairTool implements Tool {
           }
           fileWriter.setCodec(codecFactory);
           int result = innerRecover(fileReader, fileWriter, out, err, recoverPrior,
-              recoverAfter, schema, outfile);
+            recoverAfter, schema, outfile);
           return result;
         } catch (Exception e) {
           e.printStackTrace(err);
@@ -154,11 +153,9 @@ public class DataFileRepairTool implements Tool {
         }
       } else {
         return innerRecover(fileReader, null, out, err, recoverPrior,
-            recoverAfter, null, null);
+          recoverAfter, null, null);
       }
 
-    } finally {
-      fileReader.close();
     }
   }
 
diff --git a/lang/java/tools/src/main/java/org/apache/avro/tool/IdlTool.java b/lang/java/tools/src/main/java/org/apache/avro/tool/IdlTool.java
index bcc4b75..79f0aac 100644
--- a/lang/java/tools/src/main/java/org/apache/avro/tool/IdlTool.java
+++ b/lang/java/tools/src/main/java/org/apache/avro/tool/IdlTool.java
@@ -42,7 +42,7 @@ public class IdlTool implements Tool {
         (args.size() == 1 && (args.get(0).equals("--help") ||
                               args.get(0).equals("-help")))) {
       err.println("Usage: idl [in] [out]");
-      err.println("");
+      err.println();
       err.println("If an output path is not specified, outputs to stdout.");
       err.println("If no input or output is specified, takes input from");
       err.println("stdin and outputs to stdin.");
diff --git a/lang/java/tools/src/main/java/org/apache/avro/tool/Main.java b/lang/java/tools/src/main/java/org/apache/avro/tool/Main.java
index 3d488b2..337b475 100644
--- a/lang/java/tools/src/main/java/org/apache/avro/tool/Main.java
+++ b/lang/java/tools/src/main/java/org/apache/avro/tool/Main.java
@@ -90,18 +90,12 @@ public class Main {
       }
     }
     System.err.print("Version ");
-    InputStream versionInput = Main.class.getClassLoader().getResourceAsStream("VERSION.txt");
-    try {
+    try (InputStream versionInput = Main.class.getClassLoader().getResourceAsStream("VERSION.txt")) {
       printStream(versionInput);
-    } finally {
-      versionInput.close();
     }
     System.err.print(" of ");
-    InputStream noticeInput = Main.class.getClassLoader().getResourceAsStream("META-INF/NOTICE");
-    try {
+    try (InputStream noticeInput = Main.class.getClassLoader().getResourceAsStream("META-INF/NOTICE")) {
       printHead(noticeInput, 5);
-    } finally {
-      noticeInput.close();
     }
     System.err.println("----------------");
 
diff --git a/lang/java/tools/src/main/java/org/apache/avro/tool/RpcProtocolTool.java b/lang/java/tools/src/main/java/org/apache/avro/tool/RpcProtocolTool.java
index c2b62c7..ddc256a 100644
--- a/lang/java/tools/src/main/java/org/apache/avro/tool/RpcProtocolTool.java
+++ b/lang/java/tools/src/main/java/org/apache/avro/tool/RpcProtocolTool.java
@@ -65,17 +65,15 @@ public class RpcProtocolTool implements Tool {
 
     URI uri = URI.create(args.get(0));
 
-    Transceiver transceiver = null;
-    try {
-      transceiver = Ipc.createTransceiver(uri);
+    try (Transceiver transceiver = Ipc.createTransceiver(uri)) {
 
       // write an empty HandshakeRequest
       HandshakeRequest rq = HandshakeRequest.newBuilder()
-          .setClientHash(new MD5(new byte[16]))
-          .setServerHash(new MD5(new byte[16]))
-          .setClientProtocol(null)
-          .setMeta(new LinkedHashMap<>())
-          .build();
+        .setClientHash(new MD5(new byte[16]))
+        .setServerHash(new MD5(new byte[16]))
+        .setClientProtocol(null)
+        .setMeta(new LinkedHashMap<>())
+        .build();
 
       DatumWriter<HandshakeRequest> handshakeWriter = new SpecificDatumWriter<>(HandshakeRequest.class);
 
@@ -102,9 +100,6 @@ public class RpcProtocolTool implements Tool {
       // finally output the protocol
       out.println(p.toString(true));
 
-    } finally {
-      if( transceiver != null )
-        transceiver.close();
     }
     return 0;
   }
diff --git a/lang/java/tools/src/main/java/org/apache/avro/tool/RpcReceiveTool.java b/lang/java/tools/src/main/java/org/apache/avro/tool/RpcReceiveTool.java
index 2dd36e5..0b10c57 100644
--- a/lang/java/tools/src/main/java/org/apache/avro/tool/RpcReceiveTool.java
+++ b/lang/java/tools/src/main/java/org/apache/avro/tool/RpcReceiveTool.java
@@ -90,15 +90,12 @@ public class RpcReceiveTool implements Tool {
         throw new RuntimeException(e);
       }
       out.println();
-      new Thread() {
-        @Override
-        public void run() {
-          try {
-            Thread.sleep(1000);
-          } catch (InterruptedException e) {}
-          latch.countDown();
-        }
-      }.start();
+      new Thread(() -> {
+        try {
+          Thread.sleep(1000);
+        } catch (InterruptedException e) {}
+        latch.countDown();
+      }).start();
       return response;
     }
   }
diff --git a/lang/java/tools/src/main/java/org/apache/avro/tool/TetherTool.java b/lang/java/tools/src/main/java/org/apache/avro/tool/TetherTool.java
index 7b83059..7df618e 100644
--- a/lang/java/tools/src/main/java/org/apache/avro/tool/TetherTool.java
+++ b/lang/java/tools/src/main/java/org/apache/avro/tool/TetherTool.java
@@ -21,6 +21,7 @@ import java.io.File;
 import java.io.InputStream;
 import java.io.PrintStream;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 import org.apache.avro.Schema;
@@ -142,10 +143,7 @@ public class TetherTool implements Tool {
 
       if (line.hasOption("exec_args")) {
         String[] splitargs = line.getOptionValue("exec_args").split(" ");
-        exargs = new ArrayList<>();
-        for (String item: splitargs){
-          exargs.add(item);
-        }
+        exargs = new ArrayList<>(Arrays.asList(splitargs));
       }
       if (line.hasOption("exec_cached")) {
         cached = Boolean.parseBoolean(line.getOptionValue("exec_cached"));
diff --git a/lang/java/tools/src/main/java/org/apache/avro/tool/TrevniMetadataTool.java b/lang/java/tools/src/main/java/org/apache/avro/tool/TrevniMetadataTool.java
index c418bb0..54e5222 100644
--- a/lang/java/tools/src/main/java/org/apache/avro/tool/TrevniMetadataTool.java
+++ b/lang/java/tools/src/main/java/org/apache/avro/tool/TrevniMetadataTool.java
@@ -38,7 +38,6 @@ public class TrevniMetadataTool implements Tool {
   static final JsonFactory FACTORY = new JsonFactory();
 
   private JsonGenerator generator;
-  private ColumnFileReader reader;
 
   @Override
   public String getName() {
@@ -82,7 +81,7 @@ public class TrevniMetadataTool implements Tool {
       generator.setPrettyPrinter(pp);
     }
 
-    this.reader = new ColumnFileReader(input);
+    ColumnFileReader reader = new ColumnFileReader(input);
 
     generator.writeStartObject();
     generator.writeNumberField("rowCount", reader.getRowCount());
diff --git a/lang/java/tools/src/main/java/org/apache/avro/tool/TrevniToJsonTool.java b/lang/java/tools/src/main/java/org/apache/avro/tool/TrevniToJsonTool.java
index 170c0f5..0aeb615 100644
--- a/lang/java/tools/src/main/java/org/apache/avro/tool/TrevniToJsonTool.java
+++ b/lang/java/tools/src/main/java/org/apache/avro/tool/TrevniToJsonTool.java
@@ -40,7 +40,6 @@ public class TrevniToJsonTool implements Tool {
   static final JsonFactory FACTORY = new JsonFactory();
 
   private JsonGenerator generator;
-  private ColumnFileReader reader;
   private ColumnValues[] values;
   private String[] shortNames;
 
@@ -86,9 +85,9 @@ public class TrevniToJsonTool implements Tool {
       generator.setPrettyPrinter(pp);
     }
 
-    this.reader = new ColumnFileReader(input);
+    ColumnFileReader reader = new ColumnFileReader(input);
 
-    int columnCount = (int)reader.getColumnCount();
+    int columnCount = (int) reader.getColumnCount();
     this.values = new ColumnValues[columnCount];
     this.shortNames = new String[columnCount];
     for (int i = 0; i < columnCount; i++) {
diff --git a/lang/java/tools/src/main/java/org/apache/avro/tool/Util.java b/lang/java/tools/src/main/java/org/apache/avro/tool/Util.java
index 9c50d1c..f8577e8 100644
--- a/lang/java/tools/src/main/java/org/apache/avro/tool/Util.java
+++ b/lang/java/tools/src/main/java/org/apache/avro/tool/Util.java
@@ -243,13 +243,9 @@ class Util {
 
   /** Reads and returns the first datum in a data file. */
   static Object datumFromFile(Schema schema, String file) throws IOException {
-    DataFileReader<Object> in =
-        new DataFileReader<>(new File(file),
-                             new GenericDatumReader<>(schema));
-    try {
+    try (DataFileReader<Object> in = new DataFileReader<>(new File(file),
+      new GenericDatumReader<>(schema))) {
       return in.next();
-    } finally {
-      in.close();
     }
   }
 
diff --git a/lang/java/tools/src/test/java/org/apache/avro/tool/TestCatTool.java b/lang/java/tools/src/test/java/org/apache/avro/tool/TestCatTool.java
index 4b23125..2f8bce0 100644
--- a/lang/java/tools/src/test/java/org/apache/avro/tool/TestCatTool.java
+++ b/lang/java/tools/src/test/java/org/apache/avro/tool/TestCatTool.java
@@ -325,7 +325,7 @@ public class TestCatTool {
     assertEquals(0, returnCode);
 
     assertEquals("output should only contain the record at offset",
-      (int) OFFSET, getFirstIntDatum(output));
+      OFFSET, getFirstIntDatum(output));
   }
 
 
diff --git a/lang/java/tools/src/test/java/org/apache/avro/tool/TestCreateRandomFileTool.java b/lang/java/tools/src/test/java/org/apache/avro/tool/TestCreateRandomFileTool.java
index 69855c6..02b8a44 100644
--- a/lang/java/tools/src/test/java/org/apache/avro/tool/TestCreateRandomFileTool.java
+++ b/lang/java/tools/src/test/java/org/apache/avro/tool/TestCreateRandomFileTool.java
@@ -82,17 +82,15 @@ public class TestCreateRandomFileTool {
 
   private void check(String... extraArgs) throws Exception {
     ArrayList<String> args = new ArrayList<>();
-    args.addAll(Arrays.asList(new String[] {
-        OUT_FILE.toString(),
-        "--count", COUNT,
-        "--schema-file", SCHEMA_FILE.toString(),
-        "--seed", Long.toString(SEED)
-        }));
+    args.addAll(Arrays.asList(OUT_FILE.toString(),
+      "--count", COUNT,
+      "--schema-file", SCHEMA_FILE.toString(),
+      "--seed", Long.toString(SEED)));
     args.addAll(Arrays.asList(extraArgs));
     run(args);
 
     DataFileReader<Object> reader =
-      new DataFileReader<Object>(OUT_FILE, new GenericDatumReader<>());
+      new DataFileReader<>(OUT_FILE, new GenericDatumReader<>());
 
     Iterator<Object> found = reader.iterator();
     for (Object expected :
@@ -104,11 +102,9 @@ public class TestCreateRandomFileTool {
 
   private void checkMissingCount(String... extraArgs) throws Exception {
     ArrayList<String> args = new ArrayList<>();
-    args.addAll(Arrays.asList(new String[] {
-            OUT_FILE.toString(),
-            "--schema-file", SCHEMA_FILE.toString(),
-            "--seed", Long.toString(SEED)
-    }));
+    args.addAll(Arrays.asList(OUT_FILE.toString(),
+      "--schema-file", SCHEMA_FILE.toString(),
+      "--seed", Long.toString(SEED)));
     args.addAll(Arrays.asList(extraArgs));
     run(args);
     assertTrue(err.toString().contains("Need count (--count)"));
@@ -132,15 +128,14 @@ public class TestCreateRandomFileTool {
   @Test
   public void testStdOut() throws Exception {
     TestUtil.resetRandomSeed();
-    run(Arrays.asList(new String[]
-            { "-", "--count", COUNT, "--schema-file", SCHEMA_FILE.toString(),
-              "--seed", Long.toString(SEED) }));
+    run(Arrays.asList("-", "--count", COUNT, "--schema-file", SCHEMA_FILE.toString(),
+      "--seed", Long.toString(SEED)));
 
     byte[] file = out.toByteArray();
 
     DataFileStream<Object> reader =
-        new DataFileStream<Object>(new ByteArrayInputStream(file),
-                           new GenericDatumReader<>());
+      new DataFileStream<>(new ByteArrayInputStream(file),
+        new GenericDatumReader<>());
 
     Iterator<Object> found = reader.iterator();
     for (Object expected :
diff --git a/lang/java/tools/src/test/java/org/apache/avro/tool/TestDataFileRepairTool.java b/lang/java/tools/src/test/java/org/apache/avro/tool/TestDataFileRepairTool.java
index 191b7be..d011bfc 100644
--- a/lang/java/tools/src/test/java/org/apache/avro/tool/TestDataFileRepairTool.java
+++ b/lang/java/tools/src/test/java/org/apache/avro/tool/TestDataFileRepairTool.java
@@ -35,7 +35,6 @@ import org.apache.avro.io.BinaryData;
 import org.apache.avro.util.Utf8;
 import org.junit.*;
 import org.junit.rules.TemporaryFolder;
-import org.junit.rules.TestName;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
diff --git a/lang/java/tools/src/test/java/org/apache/avro/tool/TestRecodecTool.java b/lang/java/tools/src/test/java/org/apache/avro/tool/TestRecodecTool.java
index c2134f7..23ab49d 100644
--- a/lang/java/tools/src/test/java/org/apache/avro/tool/TestRecodecTool.java
+++ b/lang/java/tools/src/test/java/org/apache/avro/tool/TestRecodecTool.java
@@ -23,6 +23,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.PrintStream;
 import java.util.ArrayList;
+import java.util.Collections;
 
 import org.apache.avro.Schema;
 import org.apache.avro.Schema.Type;
@@ -67,8 +68,8 @@ public class TestRecodecTool {
     File deflate9OutputFile = new File(DIR.getRoot(),  "deflate-9-output.avro");
 
     new RecodecTool().run(new FileInputStream(inputFile), new PrintStream(defaultOutputFile), null, new ArrayList<>());
-    new RecodecTool().run(new FileInputStream(inputFile), new PrintStream(nullOutputFile), null, asList("--codec=null"));
-    new RecodecTool().run(new FileInputStream(inputFile), new PrintStream(deflateDefaultOutputFile), null, asList("--codec=deflate"));
+    new RecodecTool().run(new FileInputStream(inputFile), new PrintStream(nullOutputFile), null, Collections.singletonList("--codec=null"));
+    new RecodecTool().run(new FileInputStream(inputFile), new PrintStream(deflateDefaultOutputFile), null, Collections.singletonList("--codec=deflate"));
     new RecodecTool().run(new FileInputStream(inputFile), new PrintStream(deflate1OutputFile), null, asList("--codec=deflate", "--level=1"));
     new RecodecTool().run(new FileInputStream(inputFile), new PrintStream(deflate9OutputFile), null, asList("--codec=deflate", "--level=9"));
 
diff --git a/lang/java/tools/src/test/java/org/apache/avro/tool/TestRpcProtocolTool.java b/lang/java/tools/src/test/java/org/apache/avro/tool/TestRpcProtocolTool.java
index 2991505..cc870fd 100644
--- a/lang/java/tools/src/test/java/org/apache/avro/tool/TestRpcProtocolTool.java
+++ b/lang/java/tools/src/test/java/org/apache/avro/tool/TestRpcProtocolTool.java
@@ -28,6 +28,7 @@ import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.PrintStream;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 
 import static org.junit.Assert.assertEquals;
@@ -85,7 +86,7 @@ public class TestRpcProtocolTool {
     RpcProtocolTool testObject = new RpcProtocolTool();
 
     testObject.run(null, p2, System.err,
-        Arrays.asList(uriScheme + "://127.0.0.1:" + receive.server.getPort() + "/"));
+      Collections.singletonList(uriScheme + "://127.0.0.1:" + receive.server.getPort() + "/"));
 
     p2.flush();
 
diff --git a/lang/java/tools/src/test/java/org/apache/avro/tool/TestTetherTool.java b/lang/java/tools/src/test/java/org/apache/avro/tool/TestTetherTool.java
index 02118a7..6caa269 100644
--- a/lang/java/tools/src/test/java/org/apache/avro/tool/TestTetherTool.java
+++ b/lang/java/tools/src/test/java/org/apache/avro/tool/TestTetherTool.java
@@ -26,7 +26,6 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
 import java.io.FileWriter;
-import java.nio.file.Files;
 
 
 import org.apache.avro.Schema;
diff --git a/lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/AvroColumnReader.java b/lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/AvroColumnReader.java
index ffc3596..8886f21 100644
--- a/lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/AvroColumnReader.java
+++ b/lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/AvroColumnReader.java
@@ -161,11 +161,7 @@ public class AvroColumnReader<D>
 
   private void setDefault(Schema record, Field f) {
     String recordName = record.getFullName();
-    Map<String,Object> recordDefaults = defaults.get(recordName);
-    if (recordDefaults == null) {
-      recordDefaults = new HashMap<>();
-      defaults.put(recordName, recordDefaults);
-    }
+    Map<String, Object> recordDefaults = defaults.computeIfAbsent(recordName, k -> new HashMap<>());
     recordDefaults.put(f.name(), model.getDefaultValue(f));
   }
 
@@ -183,9 +179,9 @@ public class AvroColumnReader<D>
   @Override
   public D next() {
     try {
-      for (int i = 0; i < values.length; i++)
-        if (values[i] != null)
-          values[i].startRow();
+      for (ColumnValues value : values)
+        if (value != null)
+          value.startRow();
       this.column = 0;
       return (D)read(readSchema);
     } catch (IOException e) {
@@ -202,7 +198,7 @@ public class AvroColumnReader<D>
     switch (s.getType()) {
     case MAP:
       int size = values[column].nextLength();
-      Map map = (Map)new HashMap(size);
+      Map map = new HashMap(size);
       for (int i = 0; i < size; i++) {
         this.column = startColumn;
         values[column++].nextValue();                      // null in parent
@@ -223,7 +219,7 @@ public class AvroColumnReader<D>
       return record;
     case ARRAY:
       int length = values[column].nextLength();
-      List elements = (List)new GenericData.Array(length, s);
+      List elements = new GenericData.Array(length, s);
       for (int i = 0; i < length; i++) {
         this.column = startColumn;
         Object value = nextValue(s, column++);
diff --git a/lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/AvroColumnator.java b/lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/AvroColumnator.java
index 4bad8a9..6da9037 100644
--- a/lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/AvroColumnator.java
+++ b/lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/AvroColumnator.java
@@ -32,19 +32,17 @@ import org.apache.avro.Schema.Field;
 /** Utility that computes the column layout of a schema. */
 class AvroColumnator {
 
-  private Schema schema;
-
   private List<ColumnMetaData> columns = new ArrayList<>();
   private List<Integer> arrayWidths = new ArrayList<>();
 
   public AvroColumnator(Schema schema) {
-    this.schema = schema;
+    Schema schema1 = schema;
     columnize(null, schema, null, false);
   }
 
   /** Return columns for the schema. */
   public ColumnMetaData[] getColumns() {
-    return columns.toArray(new ColumnMetaData[columns.size()]);
+    return columns.toArray(new ColumnMetaData[0]);
   }
 
   /** Return array giving the number of columns immediately following each
diff --git a/lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/AvroTrevniOutputFormat.java b/lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/AvroTrevniOutputFormat.java
index edd6db6..3aeda3d 100644
--- a/lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/AvroTrevniOutputFormat.java
+++ b/lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/AvroTrevniOutputFormat.java
@@ -86,11 +86,8 @@ public class AvroTrevniOutputFormat <T>
         new AvroColumnWriter<>(schema, meta, ReflectData.get());
 
       private void flush() throws IOException {
-        OutputStream out = fs.create(new Path(dir, "part-"+(part++)+EXT));
-        try {
+        try (OutputStream out = fs.create(new Path(dir, "part-" + (part++) + EXT))) {
           writer.writeTo(out);
-        } finally {
-          out.close();
         }
         writer = new AvroColumnWriter<>(schema, meta, ReflectData.get());
       }
diff --git a/lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/mapreduce/AvroTrevniRecordWriterBase.java b/lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/mapreduce/AvroTrevniRecordWriterBase.java
index c4bf836..bfa01d7 100644
--- a/lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/mapreduce/AvroTrevniRecordWriterBase.java
+++ b/lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/mapreduce/AvroTrevniRecordWriterBase.java
@@ -20,7 +20,6 @@ package org.apache.trevni.avro.mapreduce;
 
 import java.io.IOException;
 import java.io.OutputStream;
-import java.util.Iterator;
 import java.util.Map.Entry;
 
 import org.apache.avro.Schema;
@@ -104,11 +103,8 @@ public abstract class AvroTrevniRecordWriterBase<K,V, T> extends RecordWriter<K,
    * @throws IOException
    */
   public void flush() throws IOException {
-    OutputStream out = fs.create(new Path(dirPath, "part-" + (part++) + EXT));
-    try {
+    try (OutputStream out = fs.create(new Path(dirPath, "part-" + (part++) + EXT))) {
       writer.writeTo(out);
-    } finally {
-      out.close();
     }
     writer = new AvroColumnWriter<>(schema, meta, ReflectData.get());
   }
@@ -122,13 +118,11 @@ public abstract class AvroTrevniRecordWriterBase<K,V, T> extends RecordWriter<K,
 
   static ColumnFileMetaData filterMetadata(final Configuration configuration) {
     final ColumnFileMetaData meta = new ColumnFileMetaData();
-    Iterator<Entry<String, String>> keyIterator = configuration.iterator();
 
-    while (keyIterator.hasNext()) {
-      Entry<String, String> confEntry = keyIterator.next();
+    for (Entry<String, String> confEntry : configuration) {
       if (confEntry.getKey().startsWith(META_PREFIX))
         meta.put(confEntry.getKey().substring(META_PREFIX.length()), confEntry
-            .getValue().getBytes(MetaData.UTF8));
+          .getValue().getBytes(MetaData.UTF8));
     }
 
     return meta;
diff --git a/lang/java/trevni/avro/src/test/java/org/apache/trevni/avro/TestCases.java b/lang/java/trevni/avro/src/test/java/org/apache/trevni/avro/TestCases.java
index 568d4bc..b9a20dc 100644
--- a/lang/java/trevni/avro/src/test/java/org/apache/trevni/avro/TestCases.java
+++ b/lang/java/trevni/avro/src/test/java/org/apache/trevni/avro/TestCases.java
@@ -70,28 +70,21 @@ public class TestCases {
   }
 
   private void checkRead(Schema s, List<Object> data) throws Exception {
-    AvroColumnReader<Object> reader =
-      new AvroColumnReader<>(new AvroColumnReader.Params(FILE)
-                                   .setSchema(s));
-    try {
+    try (AvroColumnReader<Object> reader = new AvroColumnReader<>(new AvroColumnReader.Params(FILE)
+      .setSchema(s))) {
       for (Object datum : data)
         assertEquals(datum, reader.next());
-    } finally {
-      reader.close();
     }
   }
 
   private List<Object> fromJson(Schema schema, File file) throws Exception {
-    InputStream in = new FileInputStream(file);
     List<Object> data = new ArrayList<>();
-    try {
+    try (InputStream in = new FileInputStream(file)) {
       DatumReader reader = new GenericDatumReader(schema);
       Decoder decoder = DecoderFactory.get().jsonDecoder(schema, in);
       while (true)
         data.add(reader.read(null, decoder));
     } catch (EOFException e) {
-    } finally {
-      in.close();
     }
     return data;
   }
diff --git a/lang/java/trevni/avro/src/test/java/org/apache/trevni/avro/WordCountUtil.java b/lang/java/trevni/avro/src/test/java/org/apache/trevni/avro/WordCountUtil.java
index 9b5598a..f35c97c 100644
--- a/lang/java/trevni/avro/src/test/java/org/apache/trevni/avro/WordCountUtil.java
+++ b/lang/java/trevni/avro/src/test/java/org/apache/trevni/avro/WordCountUtil.java
@@ -66,7 +66,7 @@ public class WordCountUtil {
       StringTokenizer tokens = new StringTokenizer(line);
       while (tokens.hasMoreTokens()) {
         String word = tokens.nextToken();
-        long count = COUNTS.containsKey(word) ? COUNTS.get(word) : 0L;
+        long count = COUNTS.getOrDefault(word, 0L);
         count++;
         total++;
         COUNTS.put(word, count);
@@ -109,7 +109,7 @@ public class WordCountUtil {
           new AvroColumnReader.Params(countFiles).setModel(SpecificData.get()));
     int numWords = 0;
     for (GenericRecord  wc : reader) {
-      assertEquals((String)wc.get("key"), COUNTS.get(wc.get("key")), (Long)wc.get("value"));
+      assertEquals((String)wc.get("key"), COUNTS.get(wc.get("key")), wc.get("value"));
       //assertEquals(wc.getKey(), COUNTS.get(wc.getKey()), wc.getValue());
       numWords++;
     }
diff --git a/lang/java/trevni/core/src/main/java/org/apache/trevni/BZip2Codec.java b/lang/java/trevni/core/src/main/java/org/apache/trevni/BZip2Codec.java
index f99a279..62f39fc 100644
--- a/lang/java/trevni/core/src/main/java/org/apache/trevni/BZip2Codec.java
+++ b/lang/java/trevni/core/src/main/java/org/apache/trevni/BZip2Codec.java
@@ -33,12 +33,9 @@ public class BZip2Codec extends Codec {
   @Override
   ByteBuffer compress(ByteBuffer uncompressedData) throws IOException {
     ByteArrayOutputStream baos = getOutputBuffer(uncompressedData.remaining());
-    BZip2CompressorOutputStream outputStream = new BZip2CompressorOutputStream(baos);
 
-    try {
+    try (BZip2CompressorOutputStream outputStream = new BZip2CompressorOutputStream(baos)) {
       outputStream.write(uncompressedData.array());
-    } finally {
-      outputStream.close();
     }
 
     ByteBuffer result = ByteBuffer.wrap(baos.toByteArray());
@@ -48,22 +45,19 @@ public class BZip2Codec extends Codec {
   @Override
   ByteBuffer decompress(ByteBuffer compressedData) throws IOException {
     ByteArrayInputStream bais = new ByteArrayInputStream(compressedData.array());
-    BZip2CompressorInputStream inputStream = new BZip2CompressorInputStream(bais);
-    try {
+    try (BZip2CompressorInputStream inputStream = new BZip2CompressorInputStream(bais)) {
       ByteArrayOutputStream baos = new ByteArrayOutputStream();
 
       byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
 
       int readCount = -1;
 
-      while ( (readCount = inputStream.read(buffer, compressedData.position(), buffer.length))> 0) {
+      while ((readCount = inputStream.read(buffer, compressedData.position(), buffer.length)) > 0) {
         baos.write(buffer, 0, readCount);
       }
 
       ByteBuffer result = ByteBuffer.wrap(baos.toByteArray());
       return result;
-    } finally {
-      inputStream.close();
     }
   }
 
diff --git a/lang/java/trevni/core/src/main/java/org/apache/trevni/ColumnFileWriter.java b/lang/java/trevni/core/src/main/java/org/apache/trevni/ColumnFileWriter.java
index 0b67cc7..c4eba6a 100644
--- a/lang/java/trevni/core/src/main/java/org/apache/trevni/ColumnFileWriter.java
+++ b/lang/java/trevni/core/src/main/java/org/apache/trevni/ColumnFileWriter.java
@@ -59,14 +59,13 @@ public class ColumnFileWriter {
 
   private void checkColumns(ColumnMetaData[] columnMeta) {
     Set<String> seen = new HashSet<>();
-    for (int i = 0; i < columnMeta.length; i++) {
-      ColumnMetaData c = columnMeta[i];
+    for (ColumnMetaData c : columnMeta) {
       String name = c.getName();
       if (seen.contains(name))
-        throw new TrevniRuntimeException("Duplicate column name: "+name);
+        throw new TrevniRuntimeException("Duplicate column name: " + name);
       ColumnMetaData parent = c.getParent();
       if (parent != null && !seen.contains(parent.getName()))
-        throw new TrevniRuntimeException("Parent must precede child: "+name);
+        throw new TrevniRuntimeException("Parent must precede child: " + name);
       seen.add(name);
     }
   }
@@ -122,11 +121,8 @@ public class ColumnFileWriter {
 
   /** Write all rows added to the named file. */
   public void writeTo(File file) throws IOException {
-    OutputStream out = new FileOutputStream(file);
-    try {
+    try (OutputStream out = new FileOutputStream(file)) {
       writeTo(out);
-    } finally {
-      out.close();
     }
   }
 
diff --git a/lang/java/trevni/core/src/main/java/org/apache/trevni/InputBuffer.java b/lang/java/trevni/core/src/main/java/org/apache/trevni/InputBuffer.java
index 86991c1..016b769 100644
--- a/lang/java/trevni/core/src/main/java/org/apache/trevni/InputBuffer.java
+++ b/lang/java/trevni/core/src/main/java/org/apache/trevni/InputBuffer.java
@@ -76,7 +76,7 @@ class InputBuffer {
   public <T extends Comparable> T readValue(ValueType type) throws IOException {
     switch (type) {
     case NULL:
-      return (T)null;
+      return null;
     case BOOLEAN:
       return (T)Boolean.valueOf(readBoolean());
     case INT:
diff --git a/lang/java/trevni/core/src/test/java/org/apache/trevni/TestBZip2Codec.java b/lang/java/trevni/core/src/test/java/org/apache/trevni/TestBZip2Codec.java
index 69b6eb8..7492819 100644
--- a/lang/java/trevni/core/src/test/java/org/apache/trevni/TestBZip2Codec.java
+++ b/lang/java/trevni/core/src/test/java/org/apache/trevni/TestBZip2Codec.java
@@ -62,8 +62,6 @@ public class TestBZip2Codec {
 
     //Every byte in the outputByteArray should equal every byte in the input array
     byte[] outputByteArray = decompressedBuffer.array();
-    for (int i = 0; i < inputByteSize; i++) {
-      inputByteArray[i] = outputByteArray[i];
-    }
+    System.arraycopy(outputByteArray, 0, inputByteArray, 0, inputByteSize);
   }
 }
diff --git a/lang/java/trevni/doc/pom.xml b/lang/java/trevni/doc/pom.xml
index d3ce79c..6ed4999 100644
--- a/lang/java/trevni/doc/pom.xml
+++ b/lang/java/trevni/doc/pom.xml
@@ -26,7 +26,6 @@
     <relativePath>..</relativePath>
   </parent>
 
-  <groupId>org.apache.avro</groupId>
   <artifactId>trevni-doc</artifactId>
   <version>1.9.0-SNAPSHOT</version>
   <packaging>pom</packaging>
diff --git a/lang/java/trevni/pom.xml b/lang/java/trevni/pom.xml
index 03aa6e2..191831c 100644
--- a/lang/java/trevni/pom.xml
+++ b/lang/java/trevni/pom.xml
@@ -29,7 +29,6 @@
 
   <artifactId>trevni-java</artifactId>
   <name>Trevni Java</name>
-  <groupId>org.apache.avro</groupId>
   <description>Trevni Java</description>
   <url>http://avro.apache.org/</url>
   <packaging>pom</packaging>


Mime
View raw message