Bug 41953 [Automatic Javadoc/Comment Formatting] Gives an NPE
When enabling the automatic formatting of Javadoc/comment sections (Preferences > Java > Work in Progress) the action "Source > Format" (Ctrl+Shift+F) fails with a null pointer exception. Reason: Call to "IDocument.getPartition(int)" in "org.eclipse.jdt.internal.ui.text.comment.CommentFormatter#format(String, int, int[], String) : String" returns "IDocument.DEFAULT_CONTENT_TYPE", for which no comment factory object is available. Fix: Correct fix is to use "IDocumentExtension3#getPartition(String, int)" with IJavaPartitions.JAVA_PARTITIONING to get the correct partition type.
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/comment/CommentFormatter.java
private final ISourceViewer fSourceViewer;
	/**
	 * Creates a new comment formatter.
	 * 
	 * @param viewer The source viewer where to apply the formatting strategy
	 */
	public CommentFormatter(ISourceViewer viewer) {
		fSourceViewer= viewer;
	}
	/*
	 * @see org.eclipse.jdt.core.ICodeFormatter#format(java.lang.String, int, int[], java.lang.String)
	 */
	public String format(String string, int indentationLevel, int[] positions, String lineSeparator) {
		try {
			final CommentRegion region= CommentObjectFactory.getRegion(fSourceViewer.getDocument(), fSourceViewer.getDocument().getPartition(0), lineSeparator);
			region.formatRegion();
		} catch (BadLocationException e) {
		}
		
		return null;
	}
}