-
Notifications
You must be signed in to change notification settings - Fork 917
NPEs in JUnitOutputListenerProvider
#8433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -316,7 +316,13 @@ static boolean isFullJavaId(String possibleNewRunningTestClass) { | |
| } | ||
| if (null != outputDir) { | ||
| createSession(outputDir); | ||
| project2outputDirs.put(visitor.getContext().getCurrentProject(), outputDir); | ||
| OutputVisitor.Context context = visitor.getContext(); | ||
| if (context != null) { | ||
| Project currentProject = context.getCurrentProject(); | ||
| if (currentProject != null) { | ||
| project2outputDirs.put(currentProject, outputDir); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -325,10 +331,13 @@ private String getReportsDirectory(String groupId, String artifactId, String goa | |
| MavenProject currentProject = null; | ||
| // get maven module from context if available | ||
| OutputVisitor.Context context = visitor.getContext(); | ||
| if (context != null && context.getCurrentProject() != null) { | ||
| NbMavenProject subProject = context.getCurrentProject().getLookup().lookup(NbMavenProject.class); | ||
| if (subProject != null) { | ||
| currentProject = subProject.getMavenProject(); | ||
| if (context != null) { | ||
| Project cp = context.getCurrentProject(); | ||
| if (cp != null) { | ||
| NbMavenProject subProject = cp.getLookup().lookup(NbMavenProject.class); | ||
| if (subProject != null) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Ignore whitespace changes to review.) |
||
| currentProject = subProject.getMavenProject(); | ||
| } | ||
| } | ||
| } | ||
| if (currentProject == null) { | ||
|
|
@@ -590,12 +599,20 @@ private boolean usingJUnit4(MavenProject prj) { // SUREFIRE-724 | |
| if (runningTestClass != null) { | ||
| generateTest(); | ||
| } | ||
| File outputDir = project2outputDirs.remove(visitor.getContext().getCurrentProject()); | ||
| TestSession session = outputDir != null ? outputDir2sessions.remove(outputDir) : null; | ||
| if (session != null) { | ||
| CoreManager junitManager = getManagerProvider(); | ||
| if (junitManager != null) { | ||
| junitManager.sessionFinished(session); | ||
| OutputVisitor.Context context = visitor.getContext(); | ||
| if (context != null) { | ||
| Project currentProject = context.getCurrentProject(); | ||
| if (currentProject != null) { | ||
| File outputDir = project2outputDirs.remove(currentProject); | ||
| if (outputDir != null) { | ||
| TestSession session = outputDir2sessions.remove(outputDir); | ||
| if (session != null) { | ||
| CoreManager junitManager = getManagerProvider(); | ||
| if (junitManager != null) { | ||
| junitManager.sessionFinished(session); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| runningTestClass = null; | ||
|
|
@@ -633,28 +650,31 @@ static Trouble constructTrouble(@NonNull String type, @NullAllowed String messag | |
| } | ||
|
|
||
| public @Override void sequenceFail(String sequenceId, OutputVisitor visitor) { | ||
| LOG.log(Level.FINE, "Got sequenceFail: {0}, line {1}", new Object[] { visitor.getContext().getCurrentProject(), visitor.getLine() }); | ||
| // try to get the failed test class. How can this be solved if it is not the first one in the list? | ||
| if(surefireRunningInParallel) { | ||
| String saveRunningTestClass = runningTestClass; | ||
|
|
||
| Project currentProject = visitor.getContext().getCurrentProject(); | ||
| for (String s : runningTestClassesInParallel) { | ||
| File outputDir = locateOutputDirAndWait(s, false); | ||
| // match the output dir to the project | ||
| if (outputDir != null) { | ||
| Project outputOwner = FileOwnerQuery.getOwner(FileUtil.toFileObject(outputDir)); | ||
| if (outputOwner == currentProject) { | ||
| LOG.log(Level.FINE, "Found unfinished test {0} in {1}, trying to finish", new Object[] { s, currentProject }); | ||
| runningTestClass = s; | ||
| if (Objects.equals(saveRunningTestClass, s)) { | ||
| saveRunningTestClass = null; | ||
| OutputVisitor.Context context = visitor.getContext(); | ||
| if (context != null) { | ||
| Project currentProject = context.getCurrentProject(); | ||
| LOG.log(Level.FINE, "Got sequenceFail: {0}, line {1}", new Object[] {currentProject, visitor.getLine()}); | ||
| // try to get the failed test class. How can this be solved if it is not the first one in the list? | ||
| if (currentProject != null && surefireRunningInParallel) { | ||
| String saveRunningTestClass = runningTestClass; | ||
|
|
||
| for (String s : runningTestClassesInParallel) { | ||
| File outputDir = locateOutputDirAndWait(s, false); | ||
| // match the output dir to the project | ||
| if (outputDir != null) { | ||
| Project outputOwner = FileOwnerQuery.getOwner(FileUtil.toFileObject(outputDir)); | ||
| if (outputOwner == currentProject) { | ||
| LOG.log(Level.FINE, "Found unfinished test {0} in {1}, trying to finish", new Object[] {s, currentProject}); | ||
| runningTestClass = s; | ||
| if (Objects.equals(saveRunningTestClass, s)) { | ||
| saveRunningTestClass = null; | ||
| } | ||
| generateTest(); | ||
| } | ||
| generateTest(); | ||
| } | ||
| } | ||
| runningTestClass = saveRunningTestClass; | ||
| } | ||
| runningTestClass = saveRunningTestClass; | ||
| } | ||
| sequenceEnd(sequenceId, visitor); | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: you could cover both with one
ifchained with&&like in the other comment. Those are pure field accessors with no extra code so it is ok to call them twice.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
netbeans/java/maven/src/org/netbeans/modules/maven/api/output/OutputVisitor.java
Line 43 in 98e53cd
finalso the current idiom seems safer in the face of potential concurrent modifications.