gradle / gradle-native

The home of Gradle's support for natively compiled languages
https://blog.gradle.org/introducing-the-new-cpp-plugins
Apache License 2.0
93 stars 8 forks source link

Do not fail with NPE when we cannot determine the VS2017 version #391

Open big-guy opened 6 years ago

big-guy commented 6 years ago

Reported on gradle/gradle: https://github.com/gradle/gradle/issues/4018

Apparently, there's a way to install VS2017 that looks different from what we expect. When that happens, we explode with a NPE.

This is distinct from https://github.com/gradle/gradle-native/issues/385 in that we just want something more friendly than a NPE for now.

tonyabbott commented 6 years ago

We've had the same NPE with Gradle 4.6 on Win10. There were a number of VS versions installed on the machine. Among them was VS2010, which appeared to be partially uninstalled. It was still being reported by vswhere.exe, but the registry keys that DefaultVisualCppMetadataProvider.getVisualCppFromRegistry() looks for were no longer present. It then returned null, and CommandLineToolVersionLocator.readInstall() doesn't handle a null return value from findVisualCppMetadata() properly, hence the NPE.

Completely uninstalling VS2010 fixed the problem.

I would think the appropriate behaviour would be to log a warning message and ignore that particular VS installation.

For reference, this is the stack trace from Gradle 4.6: Caused by: java.lang.NullPointerException at org.gradle.nativeplatform.toolchain.internal.msvcpp.version.CommandLineToolVersionLocator.readInstall(CommandLineToolVersionLocator.java:131) at org.gradle.nativeplatform.toolchain.internal.msvcpp.version.CommandLineToolVersionLocator.parseJson(CommandLineToolVersionLocator.java:99) at org.gradle.nativeplatform.toolchain.internal.msvcpp.version.CommandLineToolVersionLocator.locateInstalls(CommandLineToolVersionLocator.java:60) at org.gradle.nativeplatform.toolchain.internal.msvcpp.version.AbstractVisualStudioVersionLocator.getVisualStudioInstalls(AbstractVisualStudioVersionLocator.java:32) at org.gradle.nativeplatform.toolchain.internal.msvcpp.version.VisualStudioVersionDeterminer.getVisualStudioMetadata(VisualStudioVersionDeterminer.java:119) at org.gradle.nativeplatform.toolchain.internal.msvcpp.version.VisualStudioVersionDeterminer.getVisualStudioMetadataFromInstallDir(VisualStudioVersionDeterminer.java:39) at org.gradle.nativeplatform.toolchain.internal.msvcpp.DefaultVisualStudioLocator.locateUserSpecifiedInstall(DefaultVisualStudioLocator.java:147) at org.gradle.nativeplatform.toolchain.internal.msvcpp.DefaultVisualStudioLocator.locateDefaultVisualStudioInstall(DefaultVisualStudioLocator.java:94) at org.gradle.nativeplatform.toolchain.internal.msvcpp.VisualCppToolChain.checkAvailable(VisualCppToolChain.java:165) at org.gradle.nativeplatform.toolchain.internal.msvcpp.VisualCppToolChain.getAvailability(VisualCppToolChain.java:153) at org.gradle.nativeplatform.toolchain.internal.msvcpp.VisualCppToolChain.select(VisualCppToolChain.java:116) at org.gradle.nativeplatform.toolchain.internal.msvcpp.VisualCppToolChain.select(VisualCppToolChain.java:144) at org.gradle.nativeplatform.toolchain.internal.DefaultNativeToolChainRegistry.getForPlatform(DefaultNativeToolChainRegistry.java:76) at org.gradle.nativeplatform.toolchain.internal.DefaultNativeToolChainRegistry.getForPlatform(DefaultNativeToolChainRegistry.java:70) at org.gradle.nativeplatform.toolchain.internal.DefaultNativeToolChainRegistry.getForPlatform(DefaultNativeToolChainRegistry.java:33) at org.gradle.nativeplatform.internal.configure.NativeBinaryRules.toolChainFor(NativeBinaryRules.java:120) at org.gradle.nativeplatform.internal.configure.NativeBinaryRules.assignToolsToNativeBinary(NativeBinaryRules.java:44) at org.gradle.nativeplatform.internal.configure.NativeBinaryRules.assignTools(NativeBinaryRules.java:39) at org.gradle.nativeplatform.internal.configure.NativeBinaryRules.assignTools(NativeBinaryRules.java:34) at org.gradle.model.internal.method.WeaklyTypeReferencingMethod.invoke(WeaklyTypeReferencingMethod.java:100) at org.gradle.model.internal.inspect.DefaultModelRuleInvoker.invoke(DefaultModelRuleInvoker.java:36) at org.gradle.model.internal.inspect.MethodBackedModelAction.execute(MethodBackedModelAction.java:45) at org.gradle.model.internal.inspect.AbstractMethodRuleAction.execute(AbstractMethodRuleAction.java:48) at org.gradle.model.internal.inspect.ModelRuleExtractor$DefaultExtractedRuleSource$ContextualizedModelAction.execute(ModelRuleExtractor.java:515) at org.gradle.model.internal.registry.DefaultModelRegistry$4.run(DefaultModelRegistry.java:485) at org.gradle.model.internal.registry.RuleContext.run(RuleContext.java:42) at org.gradle.model.internal.registry.DefaultModelRegistry.fireAction(DefaultModelRegistry.java:482) ... 216 more