Skip to content

Commit

Permalink
Fix NPE in OverriddenAssignmentFixCore moveDown method (eclipse-jdt#1457
Browse files Browse the repository at this point in the history
  • Loading branch information
jjohnstn authored Jun 14, 2024
1 parent 68a3ac2 commit d2721bd
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,16 @@ private void moveDown(final CompilationUnitRewrite cuRewrite, TextEditGroup grou
Expression rhs= overridingAssignment.getRightHandSide();
String rhsText= cu.getBuffer().getText(rhs.getStartPosition(), extendedEnd(cuRewrite.getRoot(), overridingAssignment.getParent()) - rhs.getStartPosition());

String declarationText= cu.getBuffer().getText(declaration.getStartPosition(), fragment.getInitializer().getStartPosition() - declaration.getStartPosition());
String declarationText= ""; //$NON-NLS-1$
if (fragment.getInitializer() != null) {
declarationText= cu.getBuffer().getText(declaration.getStartPosition(), fragment.getInitializer().getStartPosition() - declaration.getStartPosition());
} else {
declarationText= cu.getBuffer().getText(declaration.getStartPosition(), fragment.getStartPosition() + fragment.getLength() - declaration.getStartPosition());
Hashtable<String, String> options= JavaCore.getOptions();
String spaceBeforeAssignment= options.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_ASSIGNMENT_OPERATOR) == JavaCore.INSERT ? " " : ""; //$NON-NLS-1$ //$NON-NLS-2$
String spaceAfterAssignment= options.get(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_ASSIGNMENT_OPERATOR) == JavaCore.INSERT ? " " : ""; //$NON-NLS-1$ //$NON-NLS-2$
declarationText= declarationText + spaceBeforeAssignment + "=" + spaceAfterAssignment; //$NON-NLS-1$
}
String targetText= declarationText + rhsText;
ASTRewrite astRewrite= cuRewrite.getASTRewrite();
ASTNode replacementNode= astRewrite.createStringPlaceholder(targetText, ASTNode.VARIABLE_DECLARATION_STATEMENT);
Expand Down

0 comments on commit d2721bd

Please sign in to comment.