Skip to content

Commit

Permalink
fix "Potential null pointer access" warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
EcljpseB0T authored and jukzi committed Jan 23, 2024
1 parent 35b9674 commit c21bef8
Show file tree
Hide file tree
Showing 24 changed files with 168 additions and 199 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private void removeSummaries(IProgressMonitor monitor, IAnnotationModel visualAn
return;
}

if (bags != null && !bags.isEmpty()) {
if (bags != null && !bags.isEmpty() && extension != null) {
Annotation[] deletions= new Annotation[bags.size()];
bags.toArray(deletions);
if (!isCanceled(monitor))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private void cancel() {
}

private static void logCodeMiningProviderException(Throwable e) {
if (e != null && (e instanceof CancellationException || (e.getCause() != null && e.getCause() instanceof CancellationException))) {
if (e instanceof CancellationException || e.getCause() instanceof CancellationException) {
return;
}
String PLUGIN_ID= "org.eclipse.jface.text"; //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,43 +206,30 @@ public void keyReleased(KeyEvent e) {
}

final StyledText styledText= fViewer.getTextWidget();
if (styledText != null && !styledText.isDisposed())
if (styledText != null && !styledText.isDisposed()) {
styledText.addKeyListener(fKeyListener);
fInvocationOffset= fViewer.getSelectedRange().x;
fComputedProposals= computeProposals(fInvocationOffset);

// BusyIndicator.showWhile(styledText.getDisplay(), new Runnable() {
// public void run() {

fInvocationOffset= fViewer.getSelectedRange().x;
// lazily compute proposals
// if (fComputedProposals == null) fComputedProposals= computeProposals(fContentAssistant.getCompletionPosition());
fComputedProposals= computeProposals(fInvocationOffset);

int count= (fComputedProposals == null ? 0 : fComputedProposals.length);
if (count == 0) {

if (!autoActivated)
styledText.getDisplay().beep();

int count= (fComputedProposals == null ? 0 : fComputedProposals.length);
if (count == 0) {
if (!autoActivated) {
styledText.getDisplay().beep();
}
} else {
if (count == 1 && !autoActivated && fContentAssistant.isAutoInserting()) {
insertProposal(fComputedProposals[0], (char) 0, 0, fInvocationOffset);
} else {

if (count == 1 && !autoActivated && fContentAssistant.isAutoInserting())

insertProposal(fComputedProposals[0], (char) 0, 0, fInvocationOffset);

else {

if (fLineDelimiter == null)
fLineDelimiter= styledText.getLineDelimiter();

createProposalSelector();
setProposals(fComputedProposals);
resizeProposalSelector(true);
displayProposals();
if (fLineDelimiter == null) {
fLineDelimiter= styledText.getLineDelimiter();
}
createProposalSelector();
setProposals(fComputedProposals);
resizeProposalSelector(true);
displayProposals();
}
// }
// });

}
}
return getErrorMessage();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,14 @@ public String showContextProposals(final boolean autoActivated) {
int position= fViewer.getSelectedRange().x;

IContextInformation[] contexts= computeContextInformation(position);
int count= (contexts == null ? 0 : contexts.length);
if (count == 1) {

if (contexts != null && contexts.length == 1) {
// Show context information directly
internalShowContextInfo(contexts[0], position);

} else if (count > 0) {
} else if (contexts != null && contexts.length > 0) {
// Precise context must be selected

if (fLineDelimiter == null)
if (fLineDelimiter == null) {
fLineDelimiter= styledText.getLineDelimiter();

}
createContextSelector();
setContexts(contexts);
displayContextSelector();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,9 @@ void execute(IDocument document) throws BadLocationException {
Position caretPosition= null;
try {
if (updateCaret()) {
caretPosition= new Position(caretOffset);
document.addPositionCategory(getCategory());
document.addPositionUpdater(updater);
caretPosition= new Position(caretOffset);
document.addPosition(getCategory(), caretPosition);
}

Expand All @@ -414,7 +414,7 @@ void execute(IDocument document) throws BadLocationException {
} catch (BadPositionCategoryException e) {
// ignore
} finally {
if (updateCaret()) {
if (caretPosition != null) { // i.e. updateCaret()
document.removePositionUpdater(updater);
try {
document.removePositionCategory(getCategory());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,7 @@ private void applyStyleRange(StyleRange range, boolean merge) {
if (start >= currentEnd)
continue;

StyleRange currentCopy= null;
if (end < currentEnd)
currentCopy= (StyleRange)current.clone();

StyleRange currentCopy= (end < currentEnd) ? (StyleRange) current.clone() : null;
if (start < currentStart) {
// Apply style to new default range and add it
StyleRange defaultRange= getDefaultStyleRange();
Expand Down Expand Up @@ -341,7 +338,7 @@ private void applyStyleRange(StyleRange range, boolean merge) {
current.length= Math.min(end, currentEnd) - start;
}

if (end < currentEnd) {
if (currentCopy != null) { // i.e. end < currentEnd
// Add rest of current range
currentCopy.start= end;
currentCopy.length= currentEnd - end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2030,21 +2030,23 @@ public void setEventConsumer(IEventConsumer consumer) {

@Override
public void setIndentPrefixes(String[] indentPrefixes, String contentType) {

int i= -1;
boolean ok= (indentPrefixes != null);
while (ok && ++i < indentPrefixes.length)
ok= (indentPrefixes[i] != null);
boolean ok= false;
if (indentPrefixes != null) {
ok= true;
while (ok && ++i < indentPrefixes.length) {
ok= (indentPrefixes[i] != null);
}
}

if (ok) {

if (fIndentChars == null)
if (fIndentChars == null) {
fIndentChars= new HashMap<>();

}
fIndentChars.put(contentType, indentPrefixes);

} else if (fIndentChars != null)
} else if (fIndentChars != null) {
fIndentChars.remove(contentType);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1661,7 +1661,7 @@ public String incrementalComplete() {
if (count == 0 && hideWhenNoProposals(false))
return;

if (count == 1 && canAutoInsert(proposals.get(0))) {
if (proposals != null && proposals.size() == 1 && canAutoInsert(proposals.get(0))) {
insertProposal(proposals.get(0), (char) 0, 0, fInvocationOffset);
hide();
} else {
Expand Down Expand Up @@ -1793,7 +1793,7 @@ boolean completeCommonPrefix() {

if (rightCase.size() == 1) {
ICompletionProposal proposal= rightCase.get(0);
if (canAutoInsert(proposal) && rightCasePostfix.length() > 0) {
if (canAutoInsert(proposal) && rightCasePostfix != null && rightCasePostfix.length() > 0) {
insertProposal(proposal, (char) 0, 0, fInvocationOffset);
hide();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,14 @@ public String showContextProposals(final boolean autoActivated) {
int offset= fContentAssistSubjectControlAdapter.getSelectedRange().x;

IContextInformation[] contexts= computeContextInformation(offset);
int count= (contexts == null ? 0 : contexts.length);
if (count == 1) {

if (contexts != null && contexts.length == 1) {
ContextFrame frame1= createContextFrame(contexts[0], offset);
if (isDuplicate(frame1))
validateContextInformation();
else
// Show context information directly
internalShowContextInfo(frame1);

} else if (count > 0) {
} else if (contexts != null && contexts.length > 0) {

// if any of the proposed context matches any of the contexts on the stack,
// assume that one (so, if context info is invoked repeatedly, the current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,9 @@ private void switchViewer(IDocument oldDoc, IDocument newDoc, LinkedPosition pos
}
}
if (target != fCurrentTarget) {
if (target == null) {
throw new IllegalStateException("target not found"); //$NON-NLS-1$
}
disconnect();
fCurrentTarget= target;
target.linkingFocusLost(fFramePosition, target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,8 @@ private void doPaint(GC gc) {
int annotationEnd= Math.min(p.getOffset() + p.getLength(), visible.getOffset() + visible.getLength());
annotationLength= annotationEnd - annotationOffset;
} else {
widgetRegion= extension.modelRange2WidgetRange(new Region(annotationOffset, annotationLength));
ITextViewerExtension5 ext= extension;
widgetRegion= ext.modelRange2WidgetRange(new Region(annotationOffset, annotationLength));
if (widgetRegion == null)
continue;
}
Expand All @@ -774,6 +775,7 @@ private void doPaint(GC gc) {
}

try {
@SuppressWarnings("null")
int startOffset= visible != null ? annotationOffset - visible.getOffset() : widgetRegion.getOffset();
int startLine= textWidget.getLineAtOffset(startOffset);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,17 @@ public ProjectionTextStore(IDocument masterDocument, IMinimalMapping mapping) {
fMapping= mapping;
}

private void internalError() {
throw new IllegalStateException();
}

@Override
public void set(String contents) {

IRegion masterRegion= fMapping.getCoverage();
if (masterRegion == null)
internalError();
throw new IllegalStateException();

try {
fMasterDocument.replace(masterRegion.getOffset(), masterRegion.getLength(), contents);
} catch (BadLocationException e) {
internalError();
throw new IllegalStateException(e);
}
}

Expand All @@ -105,7 +101,7 @@ public void replace(int offset, int length, String text) {
IRegion masterRegion= fMapping.toOriginRegion(fReusableRegion);
fMasterDocument.replace(masterRegion.getOffset(), masterRegion.getLength(), text);
} catch (BadLocationException e) {
internalError();
throw new IllegalStateException(e);
}
}

Expand All @@ -120,11 +116,8 @@ public char get(int offset) {
int originOffset= fMapping.toOriginOffset(offset);
return fMasterDocument.getChar(originOffset);
} catch (BadLocationException e) {
internalError();
throw new IllegalStateException(e);
}

// unreachable
return (char) 0;
}

@Override
Expand All @@ -137,10 +130,7 @@ public String get(int offset, int length) {
}
return buffer.toString();
} catch (BadLocationException e) {
internalError();
throw new IllegalStateException(e);
}

// unreachable
return null;
}
}
Loading

0 comments on commit c21bef8

Please sign in to comment.