Skip to content

[Bazel 5][objc_library]: NullPointerException thrown during Starlark evaluation (//:main_objc) - at <starlark>.create_compilation_attributes(<builtin>:0)  #14173

@jerrymarino

Description

@jerrymarino

Description of the problem / feature request:

Make variable substitution in objc_library raises a NullPointerException, seems to be missing a test for that code path and was broken recently somewhere on 5.x.x

Caused by: net.starlark.java.eval.Starlark$UncheckedEvalException: NullPointerException thrown during Starlark evaluation (//:main_objc)
        at <starlark>.create_compilation_attributes(<builtin>:0)                                     
        at <starlark>._build_common_variables(/virtual_builtins_bzl/common/objc/compilation_support.bzl:80)
        at <starlark>._objc_library_impl(/virtual_builtins_bzl/common/objc/objc_library.bzl:114)     
Caused by: java.lang.NullPointerException                                                            
        at java.base/java.lang.String.replace(Unknown Source)                                        
        at com.google.devtools.build.lib.rules.objc.ObjcStarlarkInternal.expandFlag(ObjcStarlarkInternal.java:145)
        at com.google.devtools.build.lib.rules.objc.ObjcStarlarkInternal.expandToolchainAndRuleContextVariables(ObjcStarlarkInternal.java:119)
        at com.google.devtools.build.lib.rules.objc.ObjcStarlarkInternal.createCompilationAttributes(ObjcStarlarkInternal.java:82)

Feature requests: what underlying problem are you trying to solve with this feature?

Use the make variable feature e.g. $(execpath ...) in objc_library native java rule code

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

# BUILD
exports_files(["Foo.ld", "Foo.h"])

cc_library(name="main",
srcs=["main.c"],
copts=["-DXX='$(location :Foo.ld)'"],
deps=[":Foo.ld"])

objc_library(name="main_objc",
srcs=["main.c"],
copts=["-DXX='$(location :Foo.h)'"],
data=[":Foo.h"])
touch WORKSPACE main.c Foo.ld Foo.h
echo 5.0.0-pre.20211011.2 > .bazelversion
bazel build :*

What operating system are you running Bazel on?

macOS Big Sur - on Apple ARM64

What's the output of bazel info release?

5.0.0-pre.20211011.2

If bazel info release returns "development version" or "(@Non-Git)", tell us how you built Bazel.

Use HEAD, pre-releases, of 5.0.0-pre.20211011.2

Any other information, logs, or outputs that you want to share?

Caused by: java.lang.NullPointerException                                                                                                                                                                   
        at java.base/java.lang.String.replace(Unknown Source)                                                                                                                                               
        at com.google.devtools.build.lib.rules.objc.ObjcStarlarkInternal.expandFlag(ObjcStarlarkInternal.java:145)                                                                                          
        at com.google.devtools.build.lib.rules.objc.ObjcStarlarkInternal.expandToolchainAndRuleContextVariables(ObjcStarlarkInternal.java:119)                                                              
        at com.google.devtools.build.lib.rules.objc.ObjcStarlarkInternal.createCompilationAttributes(ObjcStarlarkInternal.java:82)                                                                          
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)                                                                                                                   
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)                                                                                                                   
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)                                                                                                               
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)                                  
        at net.starlark.java.eval.MethodDescriptor.call(MethodDescriptor.java:162)                    
        at net.starlark.java.eval.BuiltinFunction.fastcall(BuiltinFunction.java:77)       

This seems break other rulesets using the native objc_rules e.g. rules_ios on Bazel 5:
bazel-ios/rules_ios#342

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3We're not considering working on this, but happy to review a PR. (No assignee)platform: appleteam-Rules-CPPIssues for C++ rulestype: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions