Skip to content

Commit b4bc69a

Browse files
committed
Guard against null stream set.
1 parent 2c215e8 commit b4bc69a

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/refactorings/ConvertToParallelStreamRefactoringProcessor.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ public Object[] getElements() {
424424
}
425425

426426
public Collection<Entrypoint> getEntryPoints(IJavaProject javaProject) {
427-
return this.projectToEntryPoints.get(javaProject);
427+
return this.projectToEntryPoints == null ? Collections.emptySet() : this.projectToEntryPoints.get(javaProject);
428428
}
429429

430430
public TimeCollector getExcludedTimeCollector() {
@@ -453,7 +453,9 @@ public int getNumberOfSkippedStreamInstances() {
453453
}
454454

455455
public Set<Stream> getOptimizableStreams() {
456-
return this.getStreamSet().parallelStream().filter(s -> !s.getStatus().hasError()).collect(Collectors.toSet());
456+
Set<Stream> streamSet = this.getStreamSet();
457+
return streamSet == null ? Collections.emptySet()
458+
: streamSet.parallelStream().filter(s -> !s.getStatus().hasError()).collect(Collectors.toSet());
457459
}
458460

459461
@Override

edu.cuny.hunter.streamrefactoring.eval/src/edu/cuny/hunter/streamrefactoring/eval/handlers/EvaluateConvertToParallelStreamRefactoringHandler.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,12 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
415415
resultsPrinter.print(nToUseForStreams);
416416

417417
// #streams.
418-
resultsPrinter.print(processor.getStreamSet().size());
418+
Set<Stream> streamSet = processor.getStreamSet();
419+
resultsPrinter.print(streamSet == null ? 0 : streamSet.size());
419420

420421
// #optimization available streams. These are the "filtered" streams.
421-
Set<Stream> candidates = processor.getStreamSet().parallelStream().filter(s -> {
422+
Set<Stream> candidates = streamSet == null ? Collections.emptySet()
423+
: streamSet.parallelStream().filter(s -> {
422424
String pluginId = FrameworkUtil.getBundle(Stream.class).getSymbolicName();
423425

424426
// error related to reachability.
@@ -444,7 +446,8 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
444446
: stream.getEnclosingType().getFullyQualifiedName());
445447

446448
// stream attributes.
447-
for (Stream stream : processor.getStreamSet()) {
449+
if (streamSet != null)
450+
for (Stream stream : streamSet) {
448451
streamAttributesPrinter.printRecord(javaProject.getElementName(), stream.getCreation(),
449452
stream.getCreation().getStartPosition(), stream.getCreation().getLength(),
450453
Util.getMethodIdentifier(stream.getEnclosingEclipseMethod()),
@@ -463,8 +466,8 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
463466
printStreamAttributesWithMultipleValues(stream.getPossibleExecutionModes(),
464467
streamExecutionModePrinter, stream, method, javaProject);
465468

466-
printStreamAttributesWithMultipleValues(stream.getPossibleOrderings(), streamOrderingPrinter,
467-
stream, method, javaProject);
469+
printStreamAttributesWithMultipleValues(stream.getPossibleOrderings(),
470+
streamOrderingPrinter, stream, method, javaProject);
468471

469472
}
470473

@@ -523,20 +526,22 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
523526

524527
// Refactoring type counts.
525528
for (Refactoring refactoring : Refactoring.values())
526-
resultsPrinter.print(processor.getStreamSet().parallelStream().map(Stream::getRefactoring)
529+
resultsPrinter.print(streamSet == null ? 0
530+
: streamSet.parallelStream().map(Stream::getRefactoring)
527531
.filter(r -> Objects.equals(r, refactoring)).count());
528532

529533
// Precondition success counts.
530534
for (PreconditionSuccess preconditionSuccess : PreconditionSuccess.values())
531-
resultsPrinter
532-
.print(processor.getStreamSet().parallelStream().map(Stream::getPassingPrecondition)
535+
resultsPrinter.print(streamSet == null ? 0
536+
: streamSet.parallelStream().map(Stream::getPassingPrecondition)
533537
.filter(pp -> Objects.equals(pp, preconditionSuccess)).count());
534538

535539
// Transformation counts.
536540
for (TransformationAction action : TransformationAction.values())
537-
resultsPrinter.print(processor.getStreamSet().parallelStream().map(Stream::getActions)
538-
.filter(Objects::nonNull).flatMap(as -> as.parallelStream())
539-
.filter(a -> Objects.equals(a, action)).count());
541+
resultsPrinter.print(streamSet == null ? 0
542+
: streamSet.parallelStream().map(Stream::getActions).filter(Objects::nonNull)
543+
.flatMap(as -> as.parallelStream()).filter(a -> Objects.equals(a, action))
544+
.count());
540545

541546
// actually perform the refactoring if there are no fatal
542547
// errors.

0 commit comments

Comments
 (0)