changeset 38616:31e503b8ea65

8049896: Clean up (Basic)JavacTask.getTypeMirror Reviewed-by: vromero
author jjg
date Fri, 27 May 2016 12:37:18 -0700
parents 9221159d84fb
children d93a7f64e231
files langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/api/BasicJavacTask.java
diffstat 1 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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)