8049896: Clean up (Basic)JavacTask.getTypeMirror
authorjjg
Fri, 27 May 2016 12:37:18 -0700
changeset 38616 31e503b8ea65
parent 38615 9221159d84fb
child 38617 d93a7f64e231
8049896: Clean up (Basic)JavacTask.getTypeMirror Reviewed-by: vromero
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/api/BasicJavacTask.java
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/api/BasicJavacTask.java	Fri May 27 10:37:46 2016 -0700
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/api/BasicJavacTask.java	Fri May 27 12:37:18 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -28,6 +28,7 @@
 import java.util.Collection;
 import java.util.LinkedHashSet;
 import java.util.Locale;
+import java.util.Objects;
 import java.util.ServiceLoader;
 import java.util.Set;
 import java.util.stream.Collectors;
@@ -130,9 +131,13 @@
     public TypeMirror getTypeMirror(Iterable<? extends Tree> path) {
         // TODO: Should complete attribution if necessary
         Tree last = null;
-        for (Tree node : path)
-            last = node;
-        return ((JCTree)last).type;
+        for (Tree node : path) {
+            last = Objects.requireNonNull(node);
+        }
+        if (last == null) {
+            throw new IllegalArgumentException("empty path");
+        }
+        return ((JCTree) last).type;
     }
 
     @Override @DefinedBy(Api.COMPILER_TREE)