Skip to content

Commit

Permalink
Fix for issue #616: add null check for top-level package
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Jul 12, 2018
1 parent bbbecef commit 43d2d59
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1543,14 +1543,19 @@ PackageBinding getPackage0(char[] name) {
}
// GROOVY add -- for GroovyCompilationUnitScope.getDefaultImports()
public PackageBinding getPackage(char[][] packageName, ModuleBinding moduleBinding) {
assert packageName != null && packageName.length == 2 : "Invalid packageName"; //$NON-NLS-1$
Binding binding = getTopLevelPackage(packageName[0]).getTypeOrPackage(packageName[1], moduleBinding);
if (binding == null || !binding.isValidBinding() || !(binding instanceof PackageBinding)) {
org.eclipse.jdt.internal.core.util.Util.log(org.eclipse.core.runtime.IStatus.WARNING,
"Invalid package binding for default import: " + CharOperation.toString(packageName)); //$NON-NLS-1$
return TheNotFoundPackage;
}
return (PackageBinding) binding;
if (packageName != null && packageName.length == 2) {
PackageBinding parent = getTopLevelPackage(packageName[0]);
if (parent != null) { // null if java/groovy runtime is not on classpath
Binding binding = parent.getTypeOrPackage(packageName[1], moduleBinding);
if ((binding instanceof PackageBinding) && binding.isValidBinding()) {
return (PackageBinding) binding;
}
}
}

org.eclipse.jdt.internal.core.util.Util.log(org.eclipse.core.runtime.IStatus.WARNING,
"Invalid package binding for default import: " + CharOperation.toString(packageName));
return TheNotFoundPackage;
}
// GROOVY end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1579,14 +1579,19 @@ PackageBinding getPackage0(char[] name) {
}
// GROOVY add -- for GroovyCompilationUnitScope.getDefaultImports()
public PackageBinding getPackage(char[][] packageName, ModuleBinding moduleBinding) {
assert packageName != null && packageName.length == 2 : "Invalid packageName"; //$NON-NLS-1$
Binding binding = getTopLevelPackage(packageName[0]).getTypeOrPackage(packageName[1], moduleBinding);
if (binding == null || !binding.isValidBinding() || !(binding instanceof PackageBinding)) {
org.eclipse.jdt.internal.core.util.Util.log(org.eclipse.core.runtime.IStatus.WARNING,
"Invalid binding for default import: " + CharOperation.toString(packageName)); //$NON-NLS-1$
return TheNotFoundPackage;
}
return (PackageBinding) binding;
if (packageName != null && packageName.length == 2) {
PackageBinding parent = getTopLevelPackage(packageName[0]);
if (parent != null) { // null if java/groovy runtime is not on classpath
Binding binding = parent.getTypeOrPackage(packageName[1], moduleBinding);
if ((binding instanceof PackageBinding) && binding.isValidBinding()) {
return (PackageBinding) binding;
}
}
}

org.eclipse.jdt.internal.core.util.Util.log(org.eclipse.core.runtime.IStatus.WARNING,
"Invalid package binding for default import: " + CharOperation.toString(packageName));
return TheNotFoundPackage;
}
// GROOVY end

Expand Down

0 comments on commit 43d2d59

Please sign in to comment.