8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
authormcimadamore
Fri, 27 Feb 2015 11:51:53 +0000
changeset 29291 076c277565f7
parent 29153 874d76e4699d
child 29292 c10d63c667cd
8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull Summary: replace getClass() with approapriate NPE checks Reviewed-by: jjg Contributed-by: aleksey.shipilev@oracle.com
langtools/src/java.compiler/share/classes/javax/tools/DiagnosticCollector.java
langtools/src/java.compiler/share/classes/javax/tools/ForwardingFileObject.java
langtools/src/java.compiler/share/classes/javax/tools/ForwardingJavaFileManager.java
langtools/src/java.compiler/share/classes/javax/tools/JavaFileObject.java
langtools/src/java.compiler/share/classes/javax/tools/SimpleJavaFileObject.java
langtools/src/jdk.compiler/share/classes/com/sun/source/util/DocTreePath.java
langtools/src/jdk.compiler/share/classes/com/sun/source/util/TreePath.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/ClassReader.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Dependencies.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/Checker.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/api/ClientCodeWrapper.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacScope.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTool.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/RegularFileObject.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/ZipArchive.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/ZipFileIndexArchive.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/nio/PathFileObject.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/BaseFileManager.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/ListBuffer.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javah/JavahTask.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/AttributeWriter.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/JavapTask.java
langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/internal/toolkit/Content.java
langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/Start.java
langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/api/JavadocTool.java
--- a/langtools/src/java.compiler/share/classes/javax/tools/DiagnosticCollector.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/java.compiler/share/classes/javax/tools/DiagnosticCollector.java	Fri Feb 27 11:51:53 2015 +0000
@@ -28,6 +28,7 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
 
 /**
  * Provides an easy way to collect diagnostics in a list.
@@ -43,7 +44,7 @@
             Collections.synchronizedList(new ArrayList<Diagnostic<? extends S>>());
 
     public void report(Diagnostic<? extends S> diagnostic) {
-        diagnostic.getClass(); // null check
+        Objects.requireNonNull(diagnostic);
         diagnostics.add(diagnostic);
     }
 
--- a/langtools/src/java.compiler/share/classes/javax/tools/ForwardingFileObject.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/java.compiler/share/classes/javax/tools/ForwardingFileObject.java	Fri Feb 27 11:51:53 2015 +0000
@@ -31,6 +31,7 @@
 import java.io.Reader;
 import java.io.Writer;
 import java.net.URI;
+import java.util.Objects;
 
 /**
  * Forwards calls to a given file object.  Subclasses of this class
@@ -53,8 +54,7 @@
      * @param fileObject delegate to this file object
      */
     protected ForwardingFileObject(F fileObject) {
-        fileObject.getClass(); // null check
-        this.fileObject = fileObject;
+        this.fileObject = Objects.requireNonNull(fileObject);
     }
 
     public URI toUri() {
--- a/langtools/src/java.compiler/share/classes/javax/tools/ForwardingJavaFileManager.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/java.compiler/share/classes/javax/tools/ForwardingJavaFileManager.java	Fri Feb 27 11:51:53 2015 +0000
@@ -27,6 +27,7 @@
 
 import java.io.IOException;
 import java.util.Iterator;
+import java.util.Objects;
 import java.util.Set;
 import javax.tools.JavaFileObject.Kind;
 
@@ -51,8 +52,7 @@
      * @param fileManager delegate to this file manager
      */
     protected ForwardingJavaFileManager(M fileManager) {
-        fileManager.getClass(); // null check
-        this.fileManager = fileManager;
+        this.fileManager = Objects.requireNonNull(fileManager);
     }
 
     /**
--- a/langtools/src/java.compiler/share/classes/javax/tools/JavaFileObject.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/java.compiler/share/classes/javax/tools/JavaFileObject.java	Fri Feb 27 11:51:53 2015 +0000
@@ -27,6 +27,7 @@
 
 import javax.lang.model.element.NestingKind;
 import javax.lang.model.element.Modifier;
+import java.util.Objects;
 
 /**
  * File abstraction for tools operating on Java&trade; programming language
@@ -78,8 +79,7 @@
          */
         public final String extension;
         private Kind(String extension) {
-            extension.getClass(); // null check
-            this.extension = extension;
+            this.extension = Objects.requireNonNull(extension);
         }
     }
 
--- a/langtools/src/java.compiler/share/classes/javax/tools/SimpleJavaFileObject.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/java.compiler/share/classes/javax/tools/SimpleJavaFileObject.java	Fri Feb 27 11:51:53 2015 +0000
@@ -28,6 +28,7 @@
 import java.io.*;
 import java.net.URI;
 import java.nio.CharBuffer;
+import java.util.Objects;
 import javax.lang.model.element.Modifier;
 import javax.lang.model.element.NestingKind;
 import javax.tools.JavaFileObject.Kind;
@@ -61,9 +62,8 @@
      * @param kind the kind of this file object
      */
     protected SimpleJavaFileObject(URI uri, Kind kind) {
-        // null checks
-        uri.getClass();
-        kind.getClass();
+        Objects.requireNonNull(uri);
+        Objects.requireNonNull(kind);
         if (uri.getPath() == null)
             throw new IllegalArgumentException("URI must have a path: " + uri);
         this.uri = uri;
--- a/langtools/src/jdk.compiler/share/classes/com/sun/source/util/DocTreePath.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/source/util/DocTreePath.java	Fri Feb 27 11:51:53 2015 +0000
@@ -27,7 +27,9 @@
 
 import com.sun.source.doctree.DocCommentTree;
 import com.sun.source.doctree.DocTree;
+
 import java.util.Iterator;
+import java.util.Objects;
 
 /**
  * A path of tree nodes, typically used to represent the sequence of ancestor
@@ -57,8 +59,8 @@
      * @return a path identifying the target node
      */
     public static DocTreePath getPath(DocTreePath path, DocTree target) {
-        path.getClass();
-        target.getClass();
+        Objects.requireNonNull(path); //null check
+        Objects.requireNonNull(target); //null check
 
         class Result extends Error {
             static final long serialVersionUID = -5942088234594905625L;
@@ -96,11 +98,8 @@
      * @param t the DocCommentTree to create the path for.
      */
     public DocTreePath(TreePath treePath, DocCommentTree t) {
-        treePath.getClass();
-        t.getClass();
-
-        this.treePath = treePath;
-        this.docComment = t;
+        this.treePath = Objects.requireNonNull(treePath);
+        this.docComment = Objects.requireNonNull(t);
         this.parent = null;
         this.leaf = t;
     }
--- a/langtools/src/jdk.compiler/share/classes/com/sun/source/util/TreePath.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/source/util/TreePath.java	Fri Feb 27 11:51:53 2015 +0000
@@ -26,6 +26,7 @@
 package com.sun.source.util;
 
 import java.util.Iterator;
+import java.util.Objects;
 
 import com.sun.source.tree.*;
 
@@ -57,8 +58,8 @@
      * @return the tree path of the target node
      */
     public static TreePath getPath(TreePath path, Tree target) {
-        path.getClass();
-        target.getClass();
+        Objects.requireNonNull(path);
+        Objects.requireNonNull(target);
 
         class Result extends Error {
             static final long serialVersionUID = -5942088234594905625L;
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/ClassReader.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/ClassReader.java	Fri Feb 27 11:51:53 2015 +0000
@@ -30,6 +30,7 @@
 import java.io.DataInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Objects;
 
 /**
  *  <p><b>This is NOT part of any supported API.
@@ -39,13 +40,9 @@
  */
 public class ClassReader {
     ClassReader(ClassFile classFile, InputStream in, Attribute.Factory attributeFactory) throws IOException {
-        // null checks
-        classFile.getClass();
-        attributeFactory.getClass();
-
-        this.classFile = classFile;
+        this.classFile = Objects.requireNonNull(classFile);
+        this.attributeFactory = Objects.requireNonNull(attributeFactory);
         this.in = new DataInputStream(new BufferedInputStream(in));
-        this.attributeFactory = attributeFactory;
     }
 
     ClassFile getClassFile() {
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Dependencies.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Dependencies.java	Fri Feb 27 11:51:53 2015 +0000
@@ -30,6 +30,7 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 import java.util.regex.Pattern;
 
@@ -43,6 +44,7 @@
 import com.sun.tools.classfile.Type.SimpleType;
 import com.sun.tools.classfile.Type.TypeParamType;
 import com.sun.tools.classfile.Type.WildcardType;
+
 import static com.sun.tools.classfile.ConstantPool.*;
 
 /**
@@ -165,8 +167,7 @@
      * @param f the finder
      */
     public void setFinder(Finder f) {
-        f.getClass(); // null check
-        finder = f;
+        finder = Objects.requireNonNull(f);
     }
 
     /**
@@ -220,8 +221,7 @@
      * @param f the filter
      */
     public void setFilter(Filter f) {
-        f.getClass(); // null check
-        filter = f;
+        filter = Objects.requireNonNull(f);
     }
 
     /**
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/Checker.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/Checker.java	Fri Feb 27 11:51:53 2015 +0000
@@ -81,6 +81,7 @@
 import com.sun.source.util.TreePath;
 import com.sun.tools.doclint.HtmlTag.AttrKind;
 import com.sun.tools.javac.tree.DocPretty;
+import com.sun.tools.javac.util.Assert;
 import com.sun.tools.javac.util.DefinedBy;
 import com.sun.tools.javac.util.DefinedBy.Api;
 import com.sun.tools.javac.util.StringUtils;
@@ -137,8 +138,7 @@
     // <editor-fold defaultstate="collapsed" desc="Top level">
 
     Checker(Env env) {
-        env.getClass();
-        this.env = env;
+        this.env = Assert.checkNonNull(env);
         tagStack = new LinkedList<>();
         implicitHeaderLevel = env.implicitHeaderLevel;
     }
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/api/ClientCodeWrapper.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/api/ClientCodeWrapper.java	Fri Feb 27 11:51:53 2015 +0000
@@ -45,6 +45,7 @@
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 
 import javax.lang.model.element.Modifier;
@@ -211,8 +212,7 @@
     protected class WrappedJavaFileManager implements JavaFileManager {
         protected JavaFileManager clientJavaFileManager;
         WrappedJavaFileManager(JavaFileManager clientJavaFileManager) {
-            clientJavaFileManager.getClass(); // null check
-            this.clientJavaFileManager = clientJavaFileManager;
+            this.clientJavaFileManager = Objects.requireNonNull(clientJavaFileManager);
         }
 
         @Override @DefinedBy(Api.COMPILER)
@@ -440,8 +440,7 @@
     protected class WrappedFileObject implements FileObject {
         protected FileObject clientFileObject;
         WrappedFileObject(FileObject clientFileObject) {
-            clientFileObject.getClass(); // null check
-            this.clientFileObject = clientFileObject;
+            this.clientFileObject = Objects.requireNonNull(clientFileObject);
         }
 
         @Override @DefinedBy(Api.COMPILER)
@@ -607,8 +606,7 @@
     protected class WrappedDiagnosticListener<T /*super JavaFileObject*/> implements DiagnosticListener<T> {
         protected DiagnosticListener<T> clientDiagnosticListener;
         WrappedDiagnosticListener(DiagnosticListener<T> clientDiagnosticListener) {
-            clientDiagnosticListener.getClass(); // null check
-            this.clientDiagnosticListener = clientDiagnosticListener;
+            this.clientDiagnosticListener = Objects.requireNonNull(clientDiagnosticListener);
         }
 
         @Override @DefinedBy(Api.COMPILER)
@@ -689,8 +687,7 @@
     protected class WrappedTaskListener implements TaskListener {
         protected TaskListener clientTaskListener;
         WrappedTaskListener(TaskListener clientTaskListener) {
-            clientTaskListener.getClass(); // null check
-            this.clientTaskListener = clientTaskListener;
+            this.clientTaskListener = Objects.requireNonNull(clientTaskListener);
         }
 
         @Override @DefinedBy(Api.COMPILER_TREE)
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacScope.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacScope.java	Fri Feb 27 11:51:53 2015 +0000
@@ -34,8 +34,7 @@
 import com.sun.tools.javac.comp.Env;
 import com.sun.tools.javac.util.DefinedBy;
 import com.sun.tools.javac.util.DefinedBy.Api;
-
-
+import com.sun.tools.javac.util.Assert;
 
 /**
  * Provides an implementation of Scope.
@@ -67,8 +66,7 @@
     protected final Env<AttrContext> env;
 
     private JavacScope(Env<AttrContext> env) {
-        env.getClass(); // null-check
-        this.env = env;
+        this.env = Assert.checkNonNull(env);
     }
 
     @DefinedBy(Api.COMPILER_TREE)
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java	Fri Feb 27 11:51:53 2015 +0000
@@ -108,7 +108,7 @@
 
     @Override @DefinedBy(Api.COMPILER)
     public void setProcessors(Iterable<? extends Processor> processors) {
-        processors.getClass(); // null check
+        Objects.requireNonNull(processors);
         // not mt-safe
         if (used.get())
             throw new IllegalStateException();
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTool.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTool.java	Fri Feb 27 11:51:53 2015 +0000
@@ -34,6 +34,7 @@
 import java.util.Collections;
 import java.util.EnumSet;
 import java.util.Locale;
+import java.util.Objects;
 import java.util.Set;
 
 import javax.lang.model.SourceVersion;
@@ -124,7 +125,7 @@
 
             if (options != null) {
                 for (String option : options)
-                    option.getClass(); // null check
+                    Objects.requireNonNull(option);
             }
 
             if (classes != null) {
@@ -177,7 +178,7 @@
         if (err == null)
             err = System.err;
         for (String argument : arguments)
-            argument.getClass(); // null check
+            Objects.requireNonNull(argument);
         return com.sun.tools.javac.Main.compile(arguments, new PrintWriter(err, true));
     }
 
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java	Fri Feb 27 11:51:53 2015 +0000
@@ -49,6 +49,7 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
@@ -682,8 +683,8 @@
 
     @Override @DefinedBy(Api.COMPILER)
     public String inferBinaryName(Location location, JavaFileObject file) {
-        file.getClass(); // null check
-        location.getClass(); // null check
+        Objects.requireNonNull(file);
+        Objects.requireNonNull(location);
         // Need to match the path semantics of list(location, ...)
         Iterable<? extends Path> path = getLocationAsPaths(location);
         if (path == null) {
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java	Fri Feb 27 11:51:53 2015 +0000
@@ -44,6 +44,7 @@
 import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
@@ -784,7 +785,7 @@
     }
 
     protected LocationHandler getHandler(Location location) {
-        location.getClass(); // null check
+        Objects.requireNonNull(location);
         return handlersForLocation.get(location);
     }
 
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/RegularFileObject.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/RegularFileObject.java	Fri Feb 27 11:51:53 2015 +0000
@@ -40,6 +40,7 @@
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.text.Normalizer;
+import java.util.Objects;
 
 import javax.tools.JavaFileObject;
 
@@ -186,7 +187,7 @@
 
     @Override @DefinedBy(Api.COMPILER)
     public boolean isNameCompatible(String cn, JavaFileObject.Kind kind) {
-        cn.getClass();
+        Objects.requireNonNull(cn);
         // null check
         if (kind == Kind.OTHER && getKind() != kind) {
             return false;
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/ZipArchive.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/ZipArchive.java	Fri Feb 27 11:51:53 2015 +0000
@@ -40,6 +40,7 @@
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
@@ -254,7 +255,7 @@
 
         @Override @DefinedBy(Api.COMPILER)
         public boolean isNameCompatible(String cn, JavaFileObject.Kind k) {
-            cn.getClass();
+            Objects.requireNonNull(cn);
             // null check
             if (k == Kind.OTHER && getKind() != k) {
                 return false;
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/ZipFileIndexArchive.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/ZipFileIndexArchive.java	Fri Feb 27 11:51:53 2015 +0000
@@ -35,6 +35,7 @@
 import java.nio.CharBuffer;
 import java.nio.charset.CharsetDecoder;
 import java.nio.file.Path;
+import java.util.Objects;
 import java.util.Set;
 
 import javax.tools.JavaFileObject;
@@ -206,7 +207,7 @@
 
         @Override @DefinedBy(Api.COMPILER)
         public boolean isNameCompatible(String cn, JavaFileObject.Kind k) {
-            cn.getClass(); // null check
+            Objects.requireNonNull(cn);
             if (k == Kind.OTHER && getKind() != k)
                 return false;
             return name.equals(cn + k.extension);
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/nio/PathFileObject.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/nio/PathFileObject.java	Fri Feb 27 11:51:53 2015 +0000
@@ -39,6 +39,7 @@
 import java.nio.file.Files;
 import java.nio.file.LinkOption;
 import java.nio.file.Path;
+import java.util.Objects;
 import javax.lang.model.element.Modifier;
 import javax.lang.model.element.NestingKind;
 import javax.tools.JavaFileObject;
@@ -151,10 +152,8 @@
     }
 
     protected PathFileObject(BaseFileManager fileManager, Path path) {
-        fileManager.getClass(); // null check
-        path.getClass();        // null check
-        this.fileManager = fileManager;
-        this.path = path;
+        this.fileManager = Objects.requireNonNull(fileManager);
+        this.path = Objects.requireNonNull(path);
     }
 
     public abstract String inferBinaryName(Iterable<? extends Path> paths);
@@ -174,7 +173,7 @@
 
     @Override @DefinedBy(Api.COMPILER)
     public boolean isNameCompatible(String simpleName, Kind kind) {
-        simpleName.getClass();
+        Objects.requireNonNull(simpleName);
         // null check
         if (kind == Kind.OTHER && getKind() != kind) {
             return false;
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java	Fri Feb 27 11:51:53 2015 +0000
@@ -2443,8 +2443,7 @@
         public TypeBoundKind kind;
         public JCTree inner;
         protected JCWildcard(TypeBoundKind kind, JCTree inner) {
-            kind.getClass(); // null-check
-            this.kind = kind;
+            this.kind = Assert.checkNonNull(kind);
             this.inner = inner;
         }
         @Override
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/BaseFileManager.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/BaseFileManager.java	Fri Feb 27 11:51:53 2015 +0000
@@ -46,6 +46,7 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 
 import javax.tools.JavaFileManager;
@@ -431,13 +432,12 @@
     }
 
     protected static <T> T nullCheck(T o) {
-        o.getClass(); // null check
-        return o;
+        return Objects.requireNonNull(o);
     }
 
     protected static <T> Collection<T> nullCheck(Collection<T> it) {
         for (T t : it)
-            t.getClass(); // null check
+            Objects.requireNonNull(t);
         return it;
     }
 }
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/ListBuffer.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/ListBuffer.java	Fri Feb 27 11:51:53 2015 +0000
@@ -124,7 +124,7 @@
     /** Append an element to buffer.
      */
     public ListBuffer<A> append(A x) {
-        x.getClass(); // null check
+        Assert.checkNonNull(x);
         if (shared) copy();
         List<A> newLast = List.<A>of(x);
         if (last != null) {
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java	Fri Feb 27 11:51:53 2015 +0000
@@ -341,7 +341,7 @@
     }
 
     public void setEndPosTable(JavaFileObject name, EndPosTable endPosTable) {
-        name.getClass(); // null check
+        Assert.checkNonNull(name);
         getSource(name).setEndPosTable(endPosTable);
     }
 
@@ -373,7 +373,7 @@
     }
 
     public void setWriter(WriterKind kind, PrintWriter pw) {
-        pw.getClass();
+        Assert.checkNonNull(pw);
         switch (kind) {
             case NOTICE:    noticeWriter = pw;  break;
             case WARNING:   warnWriter = pw;    break;
@@ -383,8 +383,7 @@
     }
 
     public void setWriters(PrintWriter pw) {
-        pw.getClass();
-        noticeWriter = warnWriter = errWriter = pw;
+        noticeWriter = warnWriter = errWriter = Assert.checkNonNull(pw);
     }
 
     /**
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javah/JavahTask.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javah/JavahTask.java	Fri Feb 27 11:51:53 2015 +0000
@@ -43,6 +43,7 @@
 import java.util.Locale;
 import java.util.Map;
 import java.util.MissingResourceException;
+import java.util.Objects;
 import java.util.ResourceBundle;
 import java.util.Set;
 
@@ -268,7 +269,7 @@
         this.classes = new ArrayList<>();
         if (classes != null) {
             for (String classname: classes) {
-                classname.getClass(); // null-check
+                Objects.requireNonNull(classname);
                 this.classes.add(classname);
             }
         }
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/AttributeWriter.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/AttributeWriter.java	Fri Feb 27 11:51:53 2015 +0000
@@ -62,6 +62,8 @@
 import com.sun.tools.classfile.Synthetic_attribute;
 
 import static com.sun.tools.classfile.AccessFlags.*;
+
+import com.sun.tools.javac.util.Assert;
 import com.sun.tools.javac.util.StringUtils;
 
 /*
@@ -93,9 +95,8 @@
 
     public void write(Object owner, Attribute attr, ConstantPool constant_pool) {
         if (attr != null) {
-            // null checks
-            owner.getClass();
-            constant_pool.getClass();
+            Assert.checkNonNull(constant_pool);
+            Assert.checkNonNull(owner);
             this.constant_pool = constant_pool;
             this.owner = owner;
             attr.accept(this, null);
@@ -104,9 +105,8 @@
 
     public void write(Object owner, Attributes attrs, ConstantPool constant_pool) {
         if (attrs != null) {
-            // null checks
-            owner.getClass();
-            constant_pool.getClass();
+            Assert.checkNonNull(constant_pool);
+            Assert.checkNonNull(owner);
             this.constant_pool = constant_pool;
             this.owner = owner;
             for (Attribute attr: attrs)
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/JavapTask.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/JavapTask.java	Fri Feb 27 11:51:53 2015 +0000
@@ -53,6 +53,7 @@
 import java.util.Locale;
 import java.util.Map;
 import java.util.MissingResourceException;
+import java.util.Objects;
 import java.util.ResourceBundle;
 
 import javax.lang.model.element.Modifier;
@@ -329,7 +330,7 @@
 
         this.classes = new ArrayList<>();
         for (String classname: classes) {
-            classname.getClass(); // null-check
+            Objects.requireNonNull(classname);
             this.classes.add(classname);
         }
 
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/internal/toolkit/Content.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/internal/toolkit/Content.java	Fri Feb 27 11:51:53 2015 +0000
@@ -28,6 +28,7 @@
 import java.io.IOException;
 import java.io.StringWriter;
 import java.io.Writer;
+import java.util.Objects;
 
 import com.sun.tools.doclets.internal.toolkit.util.*;
 
@@ -112,7 +113,6 @@
      * @return the reference type if not null or else throws a null pointer exception
      */
     protected static <T> T nullCheck(T t) {
-        t.getClass();
-        return t;
+        return Objects.requireNonNull(t);
     }
 }
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/Start.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/Start.java	Fri Feb 27 11:51:53 2015 +0000
@@ -33,6 +33,7 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Map;
+import java.util.Objects;
 
 import javax.tools.JavaFileManager;
 import javax.tools.JavaFileObject;
@@ -139,8 +140,7 @@
     }
 
     public Start(Context context) {
-        context.getClass(); // null check
-        this.context = context;
+        this.context = Objects.requireNonNull(context);
         apiMode = true;
         defaultDocletClassName = standardDocletClassName;
         docletParentClassLoader = null;
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/api/JavadocTool.java	Wed Jul 05 20:22:22 2017 +0200
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/api/JavadocTool.java	Fri Feb 27 11:51:53 2015 +0000
@@ -34,6 +34,7 @@
 import java.util.Collections;
 import java.util.EnumSet;
 import java.util.Locale;
+import java.util.Objects;
 import java.util.Set;
 
 import javax.lang.model.SourceVersion;
@@ -89,7 +90,7 @@
 
             if (options != null) {
                 for (String option : options)
-                    option.getClass(); // null check
+                    Objects.requireNonNull(option);
             }
 
             if (compilationUnits != null) {