Skip to content
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

Add handling for null values in PlatformProviderUtils. #6334

Closed
Closed
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 @@ -530,7 +530,9 @@ public ToolchainContext load(
if (toolchainType != null) {
ToolchainInfo toolchainInfo =
PlatformProviderUtils.toolchain(target.getConfiguredTarget());
toolchains.put(toolchainType, toolchainInfo);
if (toolchainType != null) {
toolchains.put(toolchainType, toolchainInfo);
}
}

// Find any template variables present for this toolchain.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@

import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.analysis.ProviderCollection;
import javax.annotation.Nullable;

/** Utility methods to help locate platform-related providers. */
public class PlatformProviderUtils {

/** Retrieves and casts the {@link PlatformInfo} provider from the given target. */
public static PlatformInfo platform(ProviderCollection target) {
@Nullable
public static PlatformInfo platform(@Nullable ProviderCollection target) {
if (target == null) {
return null;
}
return target.get(PlatformInfo.PROVIDER);
}

Expand All @@ -31,7 +36,11 @@ public static Iterable<PlatformInfo> platforms(Iterable<? extends ProviderCollec
}

/** Retrieves and casts the {@link ConstraintSettingInfo} provider from the given target. */
public static ConstraintSettingInfo constraintSetting(ProviderCollection target) {
@Nullable
public static ConstraintSettingInfo constraintSetting(@Nullable ProviderCollection target) {
if (target == null) {
return null;
}
return target.get(ConstraintSettingInfo.PROVIDER);
}

Expand All @@ -42,7 +51,11 @@ public static Iterable<ConstraintSettingInfo> constraintSettings(
}

/** Retrieves and casts the {@link ConstraintValueInfo} provider from the given target. */
public static ConstraintValueInfo constraintValue(ProviderCollection target) {
@Nullable
public static ConstraintValueInfo constraintValue(@Nullable ProviderCollection target) {
if (target == null) {
return null;
}
return target.get(ConstraintValueInfo.PROVIDER);
}

Expand All @@ -53,7 +66,11 @@ public static Iterable<ConstraintValueInfo> constraintValues(
}

/** Retrieves and casts the {@link ToolchainInfo} provider from the given target. */
public static ToolchainInfo toolchain(ProviderCollection target) {
@Nullable
public static ToolchainInfo toolchain(@Nullable ProviderCollection target) {
if (target == null) {
return null;
}
return target.get(ToolchainInfo.PROVIDER);
}
}