Skip to content

Commit

Permalink
Prevent possible NPE when reading package annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
jharting committed Apr 4, 2014
1 parent b932bc8 commit 8675527
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public class WeldSEClassFileInfo implements ClassFileInfo {

private static final String PACKAGE_INFO_NAME = "package-info";

private static final String DOT_SEPARATOR = ".";

private final ClassInfo classInfo;

private final IndexView index;
Expand Down Expand Up @@ -126,7 +124,8 @@ private boolean isVetoedTypeOrPackage() {
return true;
}

ClassInfo packageInfo = index.getClassByName(DotName.createSimple(getPackageName(classInfo.name()) + DOT_SEPARATOR + PACKAGE_INFO_NAME));
final DotName packageInfoName = DotName.createComponentized(getPackageName(classInfo.name()), PACKAGE_INFO_NAME);
ClassInfo packageInfo = index.getClassByName(packageInfoName);

if (packageInfo != null && isAnnotationDeclared(packageInfo, DOT_NAME_VETOED)) {
return true;
Expand Down Expand Up @@ -167,11 +166,15 @@ private boolean hasInjectConstructor() {
return false;
}

private String getPackageName(DotName name) {
private DotName getPackageName(DotName name) {
if (name.isComponentized()) {
return name.prefix().toString();
return name.prefix();
} else {
return name.local().substring(0, name.local().lastIndexOf("."));
final int lastIndex = name.local().lastIndexOf(".");
if (lastIndex == -1) {
return name;
}
return DotName.createSimple(name.local().substring(0, lastIndex));
}
}

Expand Down

0 comments on commit 8675527

Please sign in to comment.