Skip to content

Commit fdf186c

Browse files
authored
NPE while hovering in java editor in an SWT class #45 (#46)
Made some null guarding to prevent NPE in ConstantStringHover
1 parent fb9da4d commit fdf186c

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

org.eclipse.babel.tapiji.tools.java.ui/src/org/eclipse/babel/tapiji/tools/java/ui/ConstantStringHover.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,15 @@ protected void initConstantStringAuditor() {
4646

4747
CompilationUnit cu = ASTutilsUI.getAstRoot(typeRoot);
4848

49-
if (cu == null) {
49+
// There are a lot of things that can be null here. Better test
50+
if (cu == null || cu.getJavaElement() == null || cu.getJavaElement().getResource() == null || cu.getJavaElement().getResource().getProject() == null ) {
5051
return;
5152
}
5253

5354
this.manager = ResourceBundleManager.getManager(cu.getJavaElement()
5455
.getResource().getProject());
5556

56-
// determine the element at the position of the cursur
57+
// determine the element at the position of the cursor
5758
this.csf = new ResourceAuditVisitor(null, this.manager.getProject().getName());
5859
cu.accept(this.csf);
5960
}
@@ -72,6 +73,10 @@ public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
7273
return null;
7374
}
7475

76+
if (this.csf == null || this.manager == null) {
77+
return null;
78+
}
79+
7580
String bundleName = this.csf.getBundleReference(hoverRegion);
7681
String key = this.csf.getKeyAt(hoverRegion);
7782

0 commit comments

Comments
 (0)