Skip to content

Fix NPE when calculating code coverage for Gradle projects with non-standard directory layout #8521

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface Factory<T extends CoverageCalculator> {

T moduleCoverage(
long moduleId,
BuildModuleLayout moduleLayout,
@Nullable BuildModuleLayout moduleLayout,
ExecutionSettings executionSettings,
T sessionCoverage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public JacocoCoverageCalculator sessionCoverage(long sessionId) {
@Override
public JacocoCoverageCalculator moduleCoverage(
long moduleId,
BuildModuleLayout moduleLayout,
@Nullable BuildModuleLayout moduleLayout,
ExecutionSettings executionSettings,
JacocoCoverageCalculator sessionCoverage) {
return new JacocoCoverageCalculator(
Expand Down Expand Up @@ -130,7 +130,7 @@ private JacocoCoverageCalculator(
ExecutionSettings executionSettings,
String repoRoot,
long moduleId,
BuildModuleLayout moduleLayout,
@Nullable BuildModuleLayout moduleLayout,
ModuleSignalRouter moduleSignalRouter,
@Nonnull JacocoCoverageCalculator parent) {
this.parent = parent;
Expand All @@ -149,7 +149,11 @@ private JacocoCoverageCalculator(
moduleId, SignalType.MODULE_COVERAGE_DATA_JACOCO, this::addCoverageData);
}

private void addModuleLayout(BuildModuleLayout moduleLayout) {
private void addModuleLayout(@Nullable BuildModuleLayout moduleLayout) {
if (moduleLayout == null) {
LOGGER.debug("Received null module layout, will not be able to calculate coverage");
return;
}
synchronized (coverageDataLock) {
for (SourceSet sourceSet : moduleLayout.getSourceSets()) {
if (sourceSet.getType() == SourceSet.Type.TEST) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class AndroidGradleUtils {
destinationsTree = javaTree
}

LOGGER.debug("Using destination tree: {}", destinationsTree.sourceTrees)
LOGGER.debug("Using destination tree: {}", destinationsTree.files)
return destinationsTree.files
}

Expand Down