Source:
<code>private void updateTemplateEngine(CompletionContext context) { <START> ICompilationUnit cu = (ICompilationUnit) context.getEnclosingElement().getAncestor(IJavaElement.COMPILATION_UNIT); <END> ASTParser parser = createParser(cu); IBinding res = parser.createBindings(new IJavaElement { context.getEnclosingElement() }, null); if (res.length > 0 && res[0] != null) { parser = createParser(cu); CompilationUnit cuRoot = (CompilationUnit) parser.createAST(null); ASTNode completionNode = cuRoot.findDeclaringNode(res[0].getKey()); ASTNode bestNode = new ASTNode {completionNode}; int invOffset = context.getOffset(); completionNode.accept(new ASTVisitor() { @Override public boolean visit(ExpressionStatement node) { int start = node.getStartPosition(); if (invOffset > start && start > bestNode[0].getStartPosition()) { bestNode[0] = node; } return true; } }); completionNode = bestNode[0]; ASTNode completionNodeParent = completionNode.getParent(); postfixCompletionTemplateEngine.setASTNodes(completionNode, completionNodeParent); } }</code><technical_language>getEnclosingElement() return null. This is case if org.eclipse.jdt.internal.codeassist.InternalCompletionContext.setExtended() is called CompletionEngine if a problem occurs. In situation, isExtended flag is set true providing extended context :( Example: ((akjfgksdhfk)).<<ctrltab>> currently crashes a NullPointerException. Proposal: IJavaElement enclosingElement= context.getEnclosingElement(); if (enclosingElement == null) { postfixCompletionTemplateEngine.setASTNodes(null, null); return; } This is (internal ASTNode API) code essentially did</technical_language>

Target:
private void updateTemplateEngine(CompletionContext context) { IJavaElement enclosingElement= context.getEnclosingElement(); if (enclosingElement == null) { postfixCompletionTemplateEngine.setASTNodes(null, null); return; } ICompilationUnit cu = (ICompilationUnit) enclosingElement.getAncestor(IJavaElement.COMPILATION_UNIT); ASTParser parser = createParser(cu); IBinding res = parser.createBindings(new IJavaElement { enclosingElement }, null); if (res.length > 0 && res[0] != null) { parser = createParser(cu); CompilationUnit cuRoot = (CompilationUnit) parser.createAST(null); ASTNode completionNode = cuRoot.findDeclaringNode(res[0].getKey()); ASTNode bestNode = new ASTNode {completionNode}; int invOffset = context.getOffset() - context.getToken().length - 1; completionNode.accept(new ASTVisitor() { @Override public boolean visit(ExpressionStatement node) { int start = node.getStartPosition(); if (invOffset > start && start > bestNode[0].getStartPosition()) { bestNode[0] = node; } return true; } @Override public boolean visit(SimpleName node) { int start = node.getStartPosition(); if (invOffset > start && start > bestNode[0].getStartPosition()) { bestNode[0] = node; } return true; } @Override public boolean visit(QualifiedName node) { int start = node.getStartPosition(); if (invOffset > start && start > bestNode[0].getStartPosition()) { bestNode[0] = node; } return true; } }); completionNode = bestNode[0]; ASTNode completionNodeParent = completionNode.getParent(); postfixCompletionTemplateEngine.setASTNodes(completionNode, completionNodeParent); } }