Skip to content

Commit c21bef8

Browse files
committed
fix "Potential null pointer access" warnings
1 parent 35b9674 commit c21bef8

File tree

24 files changed

+168
-199
lines changed

24 files changed

+168
-199
lines changed

bundles/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionSummary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ private void removeSummaries(IProgressMonitor monitor, IAnnotationModel visualAn
186186
return;
187187
}
188188

189-
if (bags != null && !bags.isEmpty()) {
189+
if (bags != null && !bags.isEmpty() && extension != null) {
190190
Annotation[] deletions= new Annotation[bags.size()];
191191
bags.toArray(deletions);
192192
if (!isCanceled(monitor))

bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private void cancel() {
158158
}
159159

160160
private static void logCodeMiningProviderException(Throwable e) {
161-
if (e != null && (e instanceof CancellationException || (e.getCause() != null && e.getCause() instanceof CancellationException))) {
161+
if (e instanceof CancellationException || e.getCause() instanceof CancellationException) {
162162
return;
163163
}
164164
String PLUGIN_ID= "org.eclipse.jface.text"; //$NON-NLS-1$

bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/CompletionProposalPopup2.java

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -206,43 +206,30 @@ public void keyReleased(KeyEvent e) {
206206
}
207207

208208
final StyledText styledText= fViewer.getTextWidget();
209-
if (styledText != null && !styledText.isDisposed())
209+
if (styledText != null && !styledText.isDisposed()) {
210210
styledText.addKeyListener(fKeyListener);
211+
fInvocationOffset= fViewer.getSelectedRange().x;
212+
fComputedProposals= computeProposals(fInvocationOffset);
211213

212-
// BusyIndicator.showWhile(styledText.getDisplay(), new Runnable() {
213-
// public void run() {
214-
215-
fInvocationOffset= fViewer.getSelectedRange().x;
216-
// lazily compute proposals
217-
// if (fComputedProposals == null) fComputedProposals= computeProposals(fContentAssistant.getCompletionPosition());
218-
fComputedProposals= computeProposals(fInvocationOffset);
219-
220-
int count= (fComputedProposals == null ? 0 : fComputedProposals.length);
221-
if (count == 0) {
222-
223-
if (!autoActivated)
224-
styledText.getDisplay().beep();
225-
214+
int count= (fComputedProposals == null ? 0 : fComputedProposals.length);
215+
if (count == 0) {
216+
if (!autoActivated) {
217+
styledText.getDisplay().beep();
218+
}
219+
} else {
220+
if (count == 1 && !autoActivated && fContentAssistant.isAutoInserting()) {
221+
insertProposal(fComputedProposals[0], (char) 0, 0, fInvocationOffset);
226222
} else {
227-
228-
if (count == 1 && !autoActivated && fContentAssistant.isAutoInserting())
229-
230-
insertProposal(fComputedProposals[0], (char) 0, 0, fInvocationOffset);
231-
232-
else {
233-
234-
if (fLineDelimiter == null)
235-
fLineDelimiter= styledText.getLineDelimiter();
236-
237-
createProposalSelector();
238-
setProposals(fComputedProposals);
239-
resizeProposalSelector(true);
240-
displayProposals();
223+
if (fLineDelimiter == null) {
224+
fLineDelimiter= styledText.getLineDelimiter();
241225
}
226+
createProposalSelector();
227+
setProposals(fComputedProposals);
228+
resizeProposalSelector(true);
229+
displayProposals();
242230
}
243-
// }
244-
// });
245-
231+
}
232+
}
246233
return getErrorMessage();
247234
}
248235

bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContextInformationPopup2.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,14 @@ public String showContextProposals(final boolean autoActivated) {
116116
int position= fViewer.getSelectedRange().x;
117117

118118
IContextInformation[] contexts= computeContextInformation(position);
119-
int count= (contexts == null ? 0 : contexts.length);
120-
if (count == 1) {
121-
119+
if (contexts != null && contexts.length == 1) {
122120
// Show context information directly
123121
internalShowContextInfo(contexts[0], position);
124-
125-
} else if (count > 0) {
122+
} else if (contexts != null && contexts.length > 0) {
126123
// Precise context must be selected
127-
128-
if (fLineDelimiter == null)
124+
if (fLineDelimiter == null) {
129125
fLineDelimiter= styledText.getLineDelimiter();
130-
126+
}
131127
createContextSelector();
132128
setContexts(contexts);
133129
displayContextSelector();

bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,9 @@ void execute(IDocument document) throws BadLocationException {
399399
Position caretPosition= null;
400400
try {
401401
if (updateCaret()) {
402+
caretPosition= new Position(caretOffset);
402403
document.addPositionCategory(getCategory());
403404
document.addPositionUpdater(updater);
404-
caretPosition= new Position(caretOffset);
405405
document.addPosition(getCategory(), caretPosition);
406406
}
407407

@@ -414,7 +414,7 @@ void execute(IDocument document) throws BadLocationException {
414414
} catch (BadPositionCategoryException e) {
415415
// ignore
416416
} finally {
417-
if (updateCaret()) {
417+
if (caretPosition != null) { // i.e. updateCaret()
418418
document.removePositionUpdater(updater);
419419
try {
420420
document.removePositionCategory(getCategory());

bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/TextPresentation.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,7 @@ private void applyStyleRange(StyleRange range, boolean merge) {
304304
if (start >= currentEnd)
305305
continue;
306306

307-
StyleRange currentCopy= null;
308-
if (end < currentEnd)
309-
currentCopy= (StyleRange)current.clone();
310-
307+
StyleRange currentCopy= (end < currentEnd) ? (StyleRange) current.clone() : null;
311308
if (start < currentStart) {
312309
// Apply style to new default range and add it
313310
StyleRange defaultRange= getDefaultStyleRange();
@@ -341,7 +338,7 @@ private void applyStyleRange(StyleRange range, boolean merge) {
341338
current.length= Math.min(end, currentEnd) - start;
342339
}
343340

344-
if (end < currentEnd) {
341+
if (currentCopy != null) { // i.e. end < currentEnd
345342
// Add rest of current range
346343
currentCopy.start= end;
347344
currentCopy.length= currentEnd - end;

bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,21 +2030,23 @@ public void setEventConsumer(IEventConsumer consumer) {
20302030

20312031
@Override
20322032
public void setIndentPrefixes(String[] indentPrefixes, String contentType) {
2033-
20342033
int i= -1;
2035-
boolean ok= (indentPrefixes != null);
2036-
while (ok && ++i < indentPrefixes.length)
2037-
ok= (indentPrefixes[i] != null);
2034+
boolean ok= false;
2035+
if (indentPrefixes != null) {
2036+
ok= true;
2037+
while (ok && ++i < indentPrefixes.length) {
2038+
ok= (indentPrefixes[i] != null);
2039+
}
2040+
}
20382041

20392042
if (ok) {
2040-
2041-
if (fIndentChars == null)
2043+
if (fIndentChars == null) {
20422044
fIndentChars= new HashMap<>();
2043-
2045+
}
20442046
fIndentChars.put(contentType, indentPrefixes);
2045-
2046-
} else if (fIndentChars != null)
2047+
} else if (fIndentChars != null) {
20472048
fIndentChars.remove(contentType);
2049+
}
20482050
}
20492051

20502052
@Override

bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,7 +1661,7 @@ public String incrementalComplete() {
16611661
if (count == 0 && hideWhenNoProposals(false))
16621662
return;
16631663

1664-
if (count == 1 && canAutoInsert(proposals.get(0))) {
1664+
if (proposals != null && proposals.size() == 1 && canAutoInsert(proposals.get(0))) {
16651665
insertProposal(proposals.get(0), (char) 0, 0, fInvocationOffset);
16661666
hide();
16671667
} else {
@@ -1793,7 +1793,7 @@ boolean completeCommonPrefix() {
17931793

17941794
if (rightCase.size() == 1) {
17951795
ICompletionProposal proposal= rightCase.get(0);
1796-
if (canAutoInsert(proposal) && rightCasePostfix.length() > 0) {
1796+
if (canAutoInsert(proposal) && rightCasePostfix != null && rightCasePostfix.length() > 0) {
17971797
insertProposal(proposal, (char) 0, 0, fInvocationOffset);
17981798
hide();
17991799
return true;

bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,17 +189,14 @@ public String showContextProposals(final boolean autoActivated) {
189189
int offset= fContentAssistSubjectControlAdapter.getSelectedRange().x;
190190

191191
IContextInformation[] contexts= computeContextInformation(offset);
192-
int count= (contexts == null ? 0 : contexts.length);
193-
if (count == 1) {
194-
192+
if (contexts != null && contexts.length == 1) {
195193
ContextFrame frame1= createContextFrame(contexts[0], offset);
196194
if (isDuplicate(frame1))
197195
validateContextInformation();
198196
else
199197
// Show context information directly
200198
internalShowContextInfo(frame1);
201-
202-
} else if (count > 0) {
199+
} else if (contexts != null && contexts.length > 0) {
203200

204201
// if any of the proposed context matches any of the contexts on the stack,
205202
// assume that one (so, if context info is invoked repeatedly, the current

bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/link/LinkedModeUI.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,9 @@ private void switchViewer(IDocument oldDoc, IDocument newDoc, LinkedPosition pos
950950
}
951951
}
952952
if (target != fCurrentTarget) {
953+
if (target == null) {
954+
throw new IllegalStateException("target not found"); //$NON-NLS-1$
955+
}
953956
disconnect();
954957
fCurrentTarget= target;
955958
target.linkingFocusLost(fFramePosition, target);

0 commit comments

Comments
 (0)