Prevent NullPointerException when mainArtifact is not defined I failed to write unit tests to reproduce the NPE. This requires more investigation. PiperOrigin-RevId: 362948108
diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java b/src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java index c20e651..d39c0a1 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java
@@ -277,7 +277,7 @@ && semantics.prohibitHyphensInPackagePaths() && Util.containsHyphen(src.getLabel().getPackageFragment()) // It's ok to have hyphens in main file - usually no one imports it. - && !src.getLabel().equals(mainArtifact.getOwnerLabel())) { + && (mainArtifact == null || !src.getLabel().equals(mainArtifact.getOwnerLabel()))) { ruleContext.attributeError( "srcs", src.getLabel()