8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull

Replace getClass() with approapriate NPE checks

Reviewed-by: jjg
This commit is contained in:
Aleksey Shipilev 2015-02-27 11:51:53 +00:00 committed by Maurizio Cimadamore
parent 44cc65ae49
commit ee906c96d7
30 changed files with 79 additions and 80 deletions

View File

@ -28,6 +28,7 @@ package javax.tools;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects;
/** /**
* Provides an easy way to collect diagnostics in a list. * Provides an easy way to collect diagnostics in a list.
@ -43,7 +44,7 @@ public final class DiagnosticCollector<S> implements DiagnosticListener<S> {
Collections.synchronizedList(new ArrayList<Diagnostic<? extends S>>()); Collections.synchronizedList(new ArrayList<Diagnostic<? extends S>>());
public void report(Diagnostic<? extends S> diagnostic) { public void report(Diagnostic<? extends S> diagnostic) {
diagnostic.getClass(); // null check Objects.requireNonNull(diagnostic);
diagnostics.add(diagnostic); diagnostics.add(diagnostic);
} }

View File

@ -31,6 +31,7 @@ import java.io.OutputStream;
import java.io.Reader; import java.io.Reader;
import java.io.Writer; import java.io.Writer;
import java.net.URI; import java.net.URI;
import java.util.Objects;
/** /**
* Forwards calls to a given file object. Subclasses of this class * Forwards calls to a given file object. Subclasses of this class
@ -53,8 +54,7 @@ public class ForwardingFileObject<F extends FileObject> implements FileObject {
* @param fileObject delegate to this file object * @param fileObject delegate to this file object
*/ */
protected ForwardingFileObject(F fileObject) { protected ForwardingFileObject(F fileObject) {
fileObject.getClass(); // null check this.fileObject = Objects.requireNonNull(fileObject);
this.fileObject = fileObject;
} }
public URI toUri() { public URI toUri() {

View File

@ -27,6 +27,7 @@ package javax.tools;
import java.io.IOException; import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import javax.tools.JavaFileObject.Kind; import javax.tools.JavaFileObject.Kind;
@ -51,8 +52,7 @@ public class ForwardingJavaFileManager<M extends JavaFileManager> implements Jav
* @param fileManager delegate to this file manager * @param fileManager delegate to this file manager
*/ */
protected ForwardingJavaFileManager(M fileManager) { protected ForwardingJavaFileManager(M fileManager) {
fileManager.getClass(); // null check this.fileManager = Objects.requireNonNull(fileManager);
this.fileManager = fileManager;
} }
/** /**

View File

@ -27,6 +27,7 @@ package javax.tools;
import javax.lang.model.element.NestingKind; import javax.lang.model.element.NestingKind;
import javax.lang.model.element.Modifier; import javax.lang.model.element.Modifier;
import java.util.Objects;
/** /**
* File abstraction for tools operating on Java&trade; programming language * File abstraction for tools operating on Java&trade; programming language
@ -78,8 +79,7 @@ public interface JavaFileObject extends FileObject {
*/ */
public final String extension; public final String extension;
private Kind(String extension) { private Kind(String extension) {
extension.getClass(); // null check this.extension = Objects.requireNonNull(extension);
this.extension = extension;
} }
} }

View File

@ -28,6 +28,7 @@ package javax.tools;
import java.io.*; import java.io.*;
import java.net.URI; import java.net.URI;
import java.nio.CharBuffer; import java.nio.CharBuffer;
import java.util.Objects;
import javax.lang.model.element.Modifier; import javax.lang.model.element.Modifier;
import javax.lang.model.element.NestingKind; import javax.lang.model.element.NestingKind;
import javax.tools.JavaFileObject.Kind; import javax.tools.JavaFileObject.Kind;
@ -61,9 +62,8 @@ public class SimpleJavaFileObject implements JavaFileObject {
* @param kind the kind of this file object * @param kind the kind of this file object
*/ */
protected SimpleJavaFileObject(URI uri, Kind kind) { protected SimpleJavaFileObject(URI uri, Kind kind) {
// null checks Objects.requireNonNull(uri);
uri.getClass(); Objects.requireNonNull(kind);
kind.getClass();
if (uri.getPath() == null) if (uri.getPath() == null)
throw new IllegalArgumentException("URI must have a path: " + uri); throw new IllegalArgumentException("URI must have a path: " + uri);
this.uri = uri; this.uri = uri;

View File

@ -27,7 +27,9 @@ package com.sun.source.util;
import com.sun.source.doctree.DocCommentTree; import com.sun.source.doctree.DocCommentTree;
import com.sun.source.doctree.DocTree; import com.sun.source.doctree.DocTree;
import java.util.Iterator; import java.util.Iterator;
import java.util.Objects;
/** /**
* A path of tree nodes, typically used to represent the sequence of ancestor * A path of tree nodes, typically used to represent the sequence of ancestor
@ -57,8 +59,8 @@ public class DocTreePath implements Iterable<DocTree> {
* @return a path identifying the target node * @return a path identifying the target node
*/ */
public static DocTreePath getPath(DocTreePath path, DocTree target) { public static DocTreePath getPath(DocTreePath path, DocTree target) {
path.getClass(); Objects.requireNonNull(path); //null check
target.getClass(); Objects.requireNonNull(target); //null check
class Result extends Error { class Result extends Error {
static final long serialVersionUID = -5942088234594905625L; static final long serialVersionUID = -5942088234594905625L;
@ -96,11 +98,8 @@ public class DocTreePath implements Iterable<DocTree> {
* @param t the DocCommentTree to create the path for. * @param t the DocCommentTree to create the path for.
*/ */
public DocTreePath(TreePath treePath, DocCommentTree t) { public DocTreePath(TreePath treePath, DocCommentTree t) {
treePath.getClass(); this.treePath = Objects.requireNonNull(treePath);
t.getClass(); this.docComment = Objects.requireNonNull(t);
this.treePath = treePath;
this.docComment = t;
this.parent = null; this.parent = null;
this.leaf = t; this.leaf = t;
} }

View File

@ -26,6 +26,7 @@
package com.sun.source.util; package com.sun.source.util;
import java.util.Iterator; import java.util.Iterator;
import java.util.Objects;
import com.sun.source.tree.*; import com.sun.source.tree.*;
@ -57,8 +58,8 @@ public class TreePath implements Iterable<Tree> {
* @return the tree path of the target node * @return the tree path of the target node
*/ */
public static TreePath getPath(TreePath path, Tree target) { public static TreePath getPath(TreePath path, Tree target) {
path.getClass(); Objects.requireNonNull(path);
target.getClass(); Objects.requireNonNull(target);
class Result extends Error { class Result extends Error {
static final long serialVersionUID = -5942088234594905625L; static final long serialVersionUID = -5942088234594905625L;

View File

@ -30,6 +30,7 @@ import java.io.ByteArrayInputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Objects;
/** /**
* <p><b>This is NOT part of any supported API. * <p><b>This is NOT part of any supported API.
@ -39,13 +40,9 @@ import java.io.InputStream;
*/ */
public class ClassReader { public class ClassReader {
ClassReader(ClassFile classFile, InputStream in, Attribute.Factory attributeFactory) throws IOException { ClassReader(ClassFile classFile, InputStream in, Attribute.Factory attributeFactory) throws IOException {
// null checks this.classFile = Objects.requireNonNull(classFile);
classFile.getClass(); this.attributeFactory = Objects.requireNonNull(attributeFactory);
attributeFactory.getClass();
this.classFile = classFile;
this.in = new DataInputStream(new BufferedInputStream(in)); this.in = new DataInputStream(new BufferedInputStream(in));
this.attributeFactory = attributeFactory;
} }
ClassFile getClassFile() { ClassFile getClassFile() {

View File

@ -30,6 +30,7 @@ import java.util.HashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -43,6 +44,7 @@ import com.sun.tools.classfile.Type.MethodType;
import com.sun.tools.classfile.Type.SimpleType; import com.sun.tools.classfile.Type.SimpleType;
import com.sun.tools.classfile.Type.TypeParamType; import com.sun.tools.classfile.Type.TypeParamType;
import com.sun.tools.classfile.Type.WildcardType; import com.sun.tools.classfile.Type.WildcardType;
import static com.sun.tools.classfile.ConstantPool.*; import static com.sun.tools.classfile.ConstantPool.*;
/** /**
@ -165,8 +167,7 @@ public class Dependencies {
* @param f the finder * @param f the finder
*/ */
public void setFinder(Finder f) { public void setFinder(Finder f) {
f.getClass(); // null check finder = Objects.requireNonNull(f);
finder = f;
} }
/** /**
@ -220,8 +221,7 @@ public class Dependencies {
* @param f the filter * @param f the filter
*/ */
public void setFilter(Filter f) { public void setFilter(Filter f) {
f.getClass(); // null check filter = Objects.requireNonNull(f);
filter = f;
} }
/** /**

View File

@ -81,6 +81,7 @@ import com.sun.source.util.DocTreePathScanner;
import com.sun.source.util.TreePath; import com.sun.source.util.TreePath;
import com.sun.tools.doclint.HtmlTag.AttrKind; import com.sun.tools.doclint.HtmlTag.AttrKind;
import com.sun.tools.javac.tree.DocPretty; 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;
import com.sun.tools.javac.util.DefinedBy.Api; import com.sun.tools.javac.util.DefinedBy.Api;
import com.sun.tools.javac.util.StringUtils; import com.sun.tools.javac.util.StringUtils;
@ -137,8 +138,7 @@ public class Checker extends DocTreePathScanner<Void, Void> {
// <editor-fold defaultstate="collapsed" desc="Top level"> // <editor-fold defaultstate="collapsed" desc="Top level">
Checker(Env env) { Checker(Env env) {
env.getClass(); this.env = Assert.checkNonNull(env);
this.env = env;
tagStack = new LinkedList<>(); tagStack = new LinkedList<>();
implicitHeaderLevel = env.implicitHeaderLevel; implicitHeaderLevel = env.implicitHeaderLevel;
} }

View File

@ -45,6 +45,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import javax.lang.model.element.Modifier; import javax.lang.model.element.Modifier;
@ -211,8 +212,7 @@ public class ClientCodeWrapper {
protected class WrappedJavaFileManager implements JavaFileManager { protected class WrappedJavaFileManager implements JavaFileManager {
protected JavaFileManager clientJavaFileManager; protected JavaFileManager clientJavaFileManager;
WrappedJavaFileManager(JavaFileManager clientJavaFileManager) { WrappedJavaFileManager(JavaFileManager clientJavaFileManager) {
clientJavaFileManager.getClass(); // null check this.clientJavaFileManager = Objects.requireNonNull(clientJavaFileManager);
this.clientJavaFileManager = clientJavaFileManager;
} }
@Override @DefinedBy(Api.COMPILER) @Override @DefinedBy(Api.COMPILER)
@ -440,8 +440,7 @@ public class ClientCodeWrapper {
protected class WrappedFileObject implements FileObject { protected class WrappedFileObject implements FileObject {
protected FileObject clientFileObject; protected FileObject clientFileObject;
WrappedFileObject(FileObject clientFileObject) { WrappedFileObject(FileObject clientFileObject) {
clientFileObject.getClass(); // null check this.clientFileObject = Objects.requireNonNull(clientFileObject);
this.clientFileObject = clientFileObject;
} }
@Override @DefinedBy(Api.COMPILER) @Override @DefinedBy(Api.COMPILER)
@ -607,8 +606,7 @@ public class ClientCodeWrapper {
protected class WrappedDiagnosticListener<T /*super JavaFileObject*/> implements DiagnosticListener<T> { protected class WrappedDiagnosticListener<T /*super JavaFileObject*/> implements DiagnosticListener<T> {
protected DiagnosticListener<T> clientDiagnosticListener; protected DiagnosticListener<T> clientDiagnosticListener;
WrappedDiagnosticListener(DiagnosticListener<T> clientDiagnosticListener) { WrappedDiagnosticListener(DiagnosticListener<T> clientDiagnosticListener) {
clientDiagnosticListener.getClass(); // null check this.clientDiagnosticListener = Objects.requireNonNull(clientDiagnosticListener);
this.clientDiagnosticListener = clientDiagnosticListener;
} }
@Override @DefinedBy(Api.COMPILER) @Override @DefinedBy(Api.COMPILER)
@ -689,8 +687,7 @@ public class ClientCodeWrapper {
protected class WrappedTaskListener implements TaskListener { protected class WrappedTaskListener implements TaskListener {
protected TaskListener clientTaskListener; protected TaskListener clientTaskListener;
WrappedTaskListener(TaskListener clientTaskListener) { WrappedTaskListener(TaskListener clientTaskListener) {
clientTaskListener.getClass(); // null check this.clientTaskListener = Objects.requireNonNull(clientTaskListener);
this.clientTaskListener = clientTaskListener;
} }
@Override @DefinedBy(Api.COMPILER_TREE) @Override @DefinedBy(Api.COMPILER_TREE)

View File

@ -34,8 +34,7 @@ import com.sun.tools.javac.comp.AttrContext;
import com.sun.tools.javac.comp.Env; import com.sun.tools.javac.comp.Env;
import com.sun.tools.javac.util.DefinedBy; import com.sun.tools.javac.util.DefinedBy;
import com.sun.tools.javac.util.DefinedBy.Api; import com.sun.tools.javac.util.DefinedBy.Api;
import com.sun.tools.javac.util.Assert;
/** /**
* Provides an implementation of Scope. * Provides an implementation of Scope.
@ -67,8 +66,7 @@ public class JavacScope implements com.sun.source.tree.Scope {
protected final Env<AttrContext> env; protected final Env<AttrContext> env;
private JavacScope(Env<AttrContext> env) { private JavacScope(Env<AttrContext> env) {
env.getClass(); // null-check this.env = Assert.checkNonNull(env);
this.env = env;
} }
@DefinedBy(Api.COMPILER_TREE) @DefinedBy(Api.COMPILER_TREE)

View File

@ -108,7 +108,7 @@ public class JavacTaskImpl extends BasicJavacTask {
@Override @DefinedBy(Api.COMPILER) @Override @DefinedBy(Api.COMPILER)
public void setProcessors(Iterable<? extends Processor> processors) { public void setProcessors(Iterable<? extends Processor> processors) {
processors.getClass(); // null check Objects.requireNonNull(processors);
// not mt-safe // not mt-safe
if (used.get()) if (used.get())
throw new IllegalStateException(); throw new IllegalStateException();

View File

@ -34,6 +34,7 @@ import java.nio.charset.Charset;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Locale; import java.util.Locale;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import javax.lang.model.SourceVersion; import javax.lang.model.SourceVersion;
@ -124,7 +125,7 @@ public final class JavacTool implements JavaCompiler {
if (options != null) { if (options != null) {
for (String option : options) for (String option : options)
option.getClass(); // null check Objects.requireNonNull(option);
} }
if (classes != null) { if (classes != null) {
@ -177,7 +178,7 @@ public final class JavacTool implements JavaCompiler {
if (err == null) if (err == null)
err = System.err; err = System.err;
for (String argument : arguments) for (String argument : arguments)
argument.getClass(); // null check Objects.requireNonNull(argument);
return com.sun.tools.javac.Main.compile(arguments, new PrintWriter(err, true)); return com.sun.tools.javac.Main.compile(arguments, new PrintWriter(err, true));
} }

View File

@ -49,6 +49,7 @@ import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -682,8 +683,8 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
@Override @DefinedBy(Api.COMPILER) @Override @DefinedBy(Api.COMPILER)
public String inferBinaryName(Location location, JavaFileObject file) { public String inferBinaryName(Location location, JavaFileObject file) {
file.getClass(); // null check Objects.requireNonNull(file);
location.getClass(); // null check Objects.requireNonNull(location);
// Need to match the path semantics of list(location, ...) // Need to match the path semantics of list(location, ...)
Iterable<? extends Path> path = getLocationAsPaths(location); Iterable<? extends Path> path = getLocationAsPaths(location);
if (path == null) { if (path == null) {

View File

@ -44,6 +44,7 @@ import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -784,7 +785,7 @@ public class Locations {
} }
protected LocationHandler getHandler(Location location) { protected LocationHandler getHandler(Location location) {
location.getClass(); // null check Objects.requireNonNull(location);
return handlersForLocation.get(location); return handlersForLocation.get(location);
} }

View File

@ -40,6 +40,7 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.text.Normalizer; import java.text.Normalizer;
import java.util.Objects;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
@ -186,7 +187,7 @@ class RegularFileObject extends BaseFileObject {
@Override @DefinedBy(Api.COMPILER) @Override @DefinedBy(Api.COMPILER)
public boolean isNameCompatible(String cn, JavaFileObject.Kind kind) { public boolean isNameCompatible(String cn, JavaFileObject.Kind kind) {
cn.getClass(); Objects.requireNonNull(cn);
// null check // null check
if (kind == Kind.OTHER && getKind() != kind) { if (kind == Kind.OTHER && getKind() != kind) {
return false; return false;

View File

@ -40,6 +40,7 @@ import java.nio.file.Paths;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
@ -254,7 +255,7 @@ public class ZipArchive implements Archive {
@Override @DefinedBy(Api.COMPILER) @Override @DefinedBy(Api.COMPILER)
public boolean isNameCompatible(String cn, JavaFileObject.Kind k) { public boolean isNameCompatible(String cn, JavaFileObject.Kind k) {
cn.getClass(); Objects.requireNonNull(cn);
// null check // null check
if (k == Kind.OTHER && getKind() != k) { if (k == Kind.OTHER && getKind() != k) {
return false; return false;

View File

@ -35,6 +35,7 @@ import java.nio.ByteBuffer;
import java.nio.CharBuffer; import java.nio.CharBuffer;
import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetDecoder;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
@ -206,7 +207,7 @@ public class ZipFileIndexArchive implements Archive {
@Override @DefinedBy(Api.COMPILER) @Override @DefinedBy(Api.COMPILER)
public boolean isNameCompatible(String cn, JavaFileObject.Kind k) { public boolean isNameCompatible(String cn, JavaFileObject.Kind k) {
cn.getClass(); // null check Objects.requireNonNull(cn);
if (k == Kind.OTHER && getKind() != k) if (k == Kind.OTHER && getKind() != k)
return false; return false;
return name.equals(cn + k.extension); return name.equals(cn + k.extension);

View File

@ -39,6 +39,7 @@ import java.nio.charset.CharsetDecoder;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.LinkOption; import java.nio.file.LinkOption;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Objects;
import javax.lang.model.element.Modifier; import javax.lang.model.element.Modifier;
import javax.lang.model.element.NestingKind; import javax.lang.model.element.NestingKind;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
@ -151,10 +152,8 @@ public abstract class PathFileObject implements JavaFileObject {
} }
protected PathFileObject(BaseFileManager fileManager, Path path) { protected PathFileObject(BaseFileManager fileManager, Path path) {
fileManager.getClass(); // null check this.fileManager = Objects.requireNonNull(fileManager);
path.getClass(); // null check this.path = Objects.requireNonNull(path);
this.fileManager = fileManager;
this.path = path;
} }
public abstract String inferBinaryName(Iterable<? extends Path> paths); public abstract String inferBinaryName(Iterable<? extends Path> paths);
@ -174,7 +173,7 @@ public abstract class PathFileObject implements JavaFileObject {
@Override @DefinedBy(Api.COMPILER) @Override @DefinedBy(Api.COMPILER)
public boolean isNameCompatible(String simpleName, Kind kind) { public boolean isNameCompatible(String simpleName, Kind kind) {
simpleName.getClass(); Objects.requireNonNull(simpleName);
// null check // null check
if (kind == Kind.OTHER && getKind() != kind) { if (kind == Kind.OTHER && getKind() != kind) {
return false; return false;

View File

@ -2443,8 +2443,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
public TypeBoundKind kind; public TypeBoundKind kind;
public JCTree inner; public JCTree inner;
protected JCWildcard(TypeBoundKind kind, JCTree inner) { protected JCWildcard(TypeBoundKind kind, JCTree inner) {
kind.getClass(); // null-check this.kind = Assert.checkNonNull(kind);
this.kind = kind;
this.inner = inner; this.inner = inner;
} }
@Override @Override

View File

@ -46,6 +46,7 @@ import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import javax.tools.JavaFileManager; import javax.tools.JavaFileManager;
@ -431,13 +432,12 @@ public abstract class BaseFileManager implements JavaFileManager {
} }
protected static <T> T nullCheck(T o) { protected static <T> T nullCheck(T o) {
o.getClass(); // null check return Objects.requireNonNull(o);
return o;
} }
protected static <T> Collection<T> nullCheck(Collection<T> it) { protected static <T> Collection<T> nullCheck(Collection<T> it) {
for (T t : it) for (T t : it)
t.getClass(); // null check Objects.requireNonNull(t);
return it; return it;
} }
} }

View File

@ -124,7 +124,7 @@ public class ListBuffer<A> extends AbstractQueue<A> {
/** Append an element to buffer. /** Append an element to buffer.
*/ */
public ListBuffer<A> append(A x) { public ListBuffer<A> append(A x) {
x.getClass(); // null check Assert.checkNonNull(x);
if (shared) copy(); if (shared) copy();
List<A> newLast = List.<A>of(x); List<A> newLast = List.<A>of(x);
if (last != null) { if (last != null) {

View File

@ -341,7 +341,7 @@ public class Log extends AbstractLog {
} }
public void setEndPosTable(JavaFileObject name, EndPosTable endPosTable) { public void setEndPosTable(JavaFileObject name, EndPosTable endPosTable) {
name.getClass(); // null check Assert.checkNonNull(name);
getSource(name).setEndPosTable(endPosTable); getSource(name).setEndPosTable(endPosTable);
} }
@ -373,7 +373,7 @@ public class Log extends AbstractLog {
} }
public void setWriter(WriterKind kind, PrintWriter pw) { public void setWriter(WriterKind kind, PrintWriter pw) {
pw.getClass(); Assert.checkNonNull(pw);
switch (kind) { switch (kind) {
case NOTICE: noticeWriter = pw; break; case NOTICE: noticeWriter = pw; break;
case WARNING: warnWriter = pw; break; case WARNING: warnWriter = pw; break;
@ -383,8 +383,7 @@ public class Log extends AbstractLog {
} }
public void setWriters(PrintWriter pw) { public void setWriters(PrintWriter pw) {
pw.getClass(); noticeWriter = warnWriter = errWriter = Assert.checkNonNull(pw);
noticeWriter = warnWriter = errWriter = pw;
} }
/** /**

View File

@ -43,6 +43,7 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.MissingResourceException; import java.util.MissingResourceException;
import java.util.Objects;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.Set; import java.util.Set;
@ -268,7 +269,7 @@ public class JavahTask implements NativeHeaderTool.NativeHeaderTask {
this.classes = new ArrayList<>(); this.classes = new ArrayList<>();
if (classes != null) { if (classes != null) {
for (String classname: classes) { for (String classname: classes) {
classname.getClass(); // null-check Objects.requireNonNull(classname);
this.classes.add(classname); this.classes.add(classname);
} }
} }

View File

@ -62,6 +62,8 @@ import com.sun.tools.classfile.StackMap_attribute;
import com.sun.tools.classfile.Synthetic_attribute; import com.sun.tools.classfile.Synthetic_attribute;
import static com.sun.tools.classfile.AccessFlags.*; import static com.sun.tools.classfile.AccessFlags.*;
import com.sun.tools.javac.util.Assert;
import com.sun.tools.javac.util.StringUtils; import com.sun.tools.javac.util.StringUtils;
/* /*
@ -93,9 +95,8 @@ public class AttributeWriter extends BasicWriter
public void write(Object owner, Attribute attr, ConstantPool constant_pool) { public void write(Object owner, Attribute attr, ConstantPool constant_pool) {
if (attr != null) { if (attr != null) {
// null checks Assert.checkNonNull(constant_pool);
owner.getClass(); Assert.checkNonNull(owner);
constant_pool.getClass();
this.constant_pool = constant_pool; this.constant_pool = constant_pool;
this.owner = owner; this.owner = owner;
attr.accept(this, null); attr.accept(this, null);
@ -104,9 +105,8 @@ public class AttributeWriter extends BasicWriter
public void write(Object owner, Attributes attrs, ConstantPool constant_pool) { public void write(Object owner, Attributes attrs, ConstantPool constant_pool) {
if (attrs != null) { if (attrs != null) {
// null checks Assert.checkNonNull(constant_pool);
owner.getClass(); Assert.checkNonNull(owner);
constant_pool.getClass();
this.constant_pool = constant_pool; this.constant_pool = constant_pool;
this.owner = owner; this.owner = owner;
for (Attribute attr: attrs) for (Attribute attr: attrs)

View File

@ -53,6 +53,7 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.MissingResourceException; import java.util.MissingResourceException;
import java.util.Objects;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import javax.lang.model.element.Modifier; import javax.lang.model.element.Modifier;
@ -329,7 +330,7 @@ public class JavapTask implements DisassemblerTool.DisassemblerTask, Messages {
this.classes = new ArrayList<>(); this.classes = new ArrayList<>();
for (String classname: classes) { for (String classname: classes) {
classname.getClass(); // null-check Objects.requireNonNull(classname);
this.classes.add(classname); this.classes.add(classname);
} }

View File

@ -28,6 +28,7 @@ package com.sun.tools.doclets.internal.toolkit;
import java.io.IOException; import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
import java.io.Writer; import java.io.Writer;
import java.util.Objects;
import com.sun.tools.doclets.internal.toolkit.util.*; import com.sun.tools.doclets.internal.toolkit.util.*;
@ -112,7 +113,6 @@ public abstract class Content {
* @return the reference type if not null or else throws a null pointer exception * @return the reference type if not null or else throws a null pointer exception
*/ */
protected static <T> T nullCheck(T t) { protected static <T> T nullCheck(T t) {
t.getClass(); return Objects.requireNonNull(t);
return t;
} }
} }

View File

@ -33,6 +33,7 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import javax.tools.JavaFileManager; import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
@ -139,8 +140,7 @@ public class Start extends ToolOption.Helper {
} }
public Start(Context context) { public Start(Context context) {
context.getClass(); // null check this.context = Objects.requireNonNull(context);
this.context = context;
apiMode = true; apiMode = true;
defaultDocletClassName = standardDocletClassName; defaultDocletClassName = standardDocletClassName;
docletParentClassLoader = null; docletParentClassLoader = null;

View File

@ -34,6 +34,7 @@ import java.nio.charset.Charset;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Locale; import java.util.Locale;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import javax.lang.model.SourceVersion; import javax.lang.model.SourceVersion;
@ -89,7 +90,7 @@ public class JavadocTool implements DocumentationTool {
if (options != null) { if (options != null) {
for (String option : options) for (String option : options)
option.getClass(); // null check Objects.requireNonNull(option);
} }
if (compilationUnits != null) { if (compilationUnits != null) {