java.lang.NullPointerException if python shebang is None
Created by: plmnikulin
Please, consider handling of java exceptions in the cases similar to the following. Currently there is no hint concerning particular BUCK file and line number in the error message. It is really hard to realize what has happened in the case of a large project.
/home/ubuntu/buck/buck-out/gen/ce9b6f2e/programs/buck.pex build //:custom-interpreter-test
Not using buckd because watchman isn't installed.
Parsing buck files: finished in 0.6 sec
Buck encountered an internal error
java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.NullPointerException
at com.facebook.buck.parser.TargetSpecResolver.collectTargets(TargetSpecResolver.java:360)
...
See below for the full error message.
Minimal example could be distilled further, but I suppose in the current form it gives some notion how it can happen in real life.
BUCK
file
python_binary(
name = 'custom-interpreter-test',
main_module = 'just_test_module',
platform = 'platform',
build_args = [
# Intention:
# '--python-shebang', read_config('python#platform', 'interpreter') + ' -Estt',
# Accidentally [python].platform section was missed in .buckconfig.local
'--python-shebang', read_config('python#NOTplatform', 'interpreter'),
],
deps = [
':just_test_library',
],
)
python_library(
name = 'just_test_library',
srcs = ['just_test_module.py'],
)
.buckconfig
[python#platform]
# Should be in .buckconfig.local, for CentOS-8:
# interpreter = /usr/libexec/platform-python
interpreter = /usr/bin/python3
just_test_module.py
if __name__ == '__main__':
print('Hi')
else:
raise RuntimeError('Must be called as main module')
BUCK version:
commit b2f0616214198619163c194b4c7aba0d563d1c18 (HEAD -> master, origin/master, origin/HEAD)
Author: Milen Dzhumerov <mgd@fb.com>
Date: Mon Feb 17 09:24:32 2020 -0800
OS: Ubuntu-18.04
openjdk-8-jdk-headless:
Installed: 8u242-b08-0ubuntu3~18.04
Buck encountered an internal error
java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.NullPointerException
at com.facebook.buck.parser.TargetSpecResolver.collectTargets(TargetSpecResolver.java:360)
at com.facebook.buck.parser.TargetSpecResolver.resolveTargetSpecs(TargetSpecResolver.java:256)
at com.facebook.buck.parser.ParserWithConfigurableAttributes.collectBuildTargetsFromTargetNodeSpecs(ParserWithConfigurableAttributes.java:338)
at com.facebook.buck.parser.AbstractParser.buildTargetGraphForTargetNodeSpecs(AbstractParser.java:297)
at com.facebook.buck.parser.AbstractParser.buildTargetGraphWithoutTopLevelConfigurationTargets(AbstractParser.java:271)
at com.facebook.buck.cli.BuildCommand.createUnversionedTargetGraph(BuildCommand.java:830)
at com.facebook.buck.cli.BuildCommand.createGraphsAndTargets(BuildCommand.java:399)
at com.facebook.buck.cli.BuildCommand.executeBuildAndProcessResult(BuildCommand.java:476)
at com.facebook.buck.cli.BuildCommand.run(BuildCommand.java:363)
at com.facebook.buck.cli.BuildCommand.runWithoutHelpInternal(BuildCommand.java:305)
at com.facebook.buck.cli.BuildCommand.runWithoutHelp(BuildCommand.java:287)
at com.facebook.buck.cli.AbstractCommand.run(AbstractCommand.java:280)
at com.facebook.buck.cli.AbstractContainerCommand.run(AbstractContainerCommand.java:90)
at com.facebook.buck.cli.MainRunner.runMainWithExitCode(MainRunner.java:1445)
at com.facebook.buck.cli.MainRunner.runMainThenExit(MainRunner.java:476)
at com.facebook.buck.cli.MainWithoutNailgun.main(MainWithoutNailgun.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.facebook.buck.cli.bootstrapper.ClassLoaderBootstrapper.main(ClassLoaderBootstrapper.java:55)
Caused by: java.util.concurrent.ExecutionException: java.lang.NullPointerException
at com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:528)
at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:507)
at com.google.common.util.concurrent.AbstractFuture$TrustedFuture.get(AbstractFuture.java:85)
at com.facebook.buck.parser.TargetSpecResolver.collectTargets(TargetSpecResolver.java:354)
... 20 more
Caused by: java.lang.NullPointerException
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:871)
at com.google.common.collect.ImmutableCollection$ArrayBasedBuilder.add(ImmutableCollection.java:486)
at com.google.common.collect.ImmutableList$Builder.add(ImmutableList.java:775)
at com.facebook.buck.json.BuildFilePythonResultDeserializer.deserializeList(BuildFilePythonResultDeserializer.java:113)
at com.facebook.buck.json.BuildFilePythonResultDeserializer.deserializeRecursive(BuildFilePythonResultDeserializer.java:127)
at com.facebook.buck.json.BuildFilePythonResultDeserializer.deserializeObject(BuildFilePythonResultDeserializer.java:101)
at com.facebook.buck.json.BuildFilePythonResultDeserializer.deserializeObjectList(BuildFilePythonResultDeserializer.java:88)
at com.facebook.buck.json.BuildFilePythonResultDeserializer.deserialize(BuildFilePythonResultDeserializer.java:62)
at com.facebook.buck.json.BuildFilePythonResultDeserializer.deserialize(BuildFilePythonResultDeserializer.java:42)
at com.fasterxml.jackson.databind.ObjectMapper._readValue(ObjectMapper.java:3984)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2276)
at com.fasterxml.jackson.core.JsonParser.readValueAs(JsonParser.java:1729)
at com.facebook.buck.parser.PythonDslProjectBuildFileParser.performJsonRequest(PythonDslProjectBuildFileParser.java:628)
at com.facebook.buck.parser.PythonDslProjectBuildFileParser.getAllRulesInternal(PythonDslProjectBuildFileParser.java:447)
at com.facebook.buck.parser.PythonDslProjectBuildFileParser.getManifest(PythonDslProjectBuildFileParser.java:385)
at com.facebook.buck.parser.PythonDslProjectBuildFileParser.getManifest(PythonDslProjectBuildFileParser.java:93)
at com.facebook.buck.json.TargetCountVerificationParserDecorator.getManifest(TargetCountVerificationParserDecorator.java:73)
at com.facebook.buck.json.TargetCountVerificationParserDecorator.getManifest(TargetCountVerificationParserDecorator.java:33)
at com.facebook.buck.parser.decorators.EventReportingProjectBuildFileParser.getManifest(EventReportingProjectBuildFileParser.java:69)
at com.facebook.buck.parser.decorators.EventReportingProjectBuildFileParser.getManifest(EventReportingProjectBuildFileParser.java:38)
at com.facebook.buck.parser.FileParserPool.lambda$getManifest$0(FileParserPool.java:84)
at com.facebook.buck.util.concurrent.ResourcePool$1.apply(ResourcePool.java:136)
at com.facebook.buck.util.concurrent.ResourcePool$1.apply(ResourcePool.java:128)
at com.google.common.util.concurrent.AbstractTransformFuture$AsyncTransformFuture.doTransform(AbstractTransformFuture.java:206)
at com.google.common.util.concurrent.AbstractTransformFuture$AsyncTransformFuture.doTransform(AbstractTransformFuture.java:195)
at com.google.common.util.concurrent.AbstractTransformFuture.run(AbstractTransformFuture.java:115)
at com.google.common.util.concurrent.MoreExecutors$5$1.run(MoreExecutors.java:999)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)