When changing the Launch Bar project descriptor (middle dropdown, labelled Launch Configuration) to a new project which is of a different type, this problem may occur. The issue is always reproducible, but the conditions for reproduction are very specific.
I have reproduced the problem in an ISV extended CDT product, where there are multiple project types (natures) associated with different Launch Target types.
I have not tried to reproduce the problem in vanilla CDT.
When the problem occurs a Problem Occurred popup dialog appears containing the message
"Change Build Configurations has encountered a problem"
To reproduce (always):
- Create a Core Build (eg CMake) project of type A.
- Create 2 launch targets for type A project.
- Create a Core Build (eg CMake) project of type B.
- Create 2 launch targets for type B project.
- Using the Launch Bar Launch Configuration dropdown (middle Launch Bar dropdown), change from project A to B or vice versa.
Expected: no error popup is shown and able to build the selected project.
Actual: An error popup displays the message "Change Build Configurations has encountered a problem"
Supplemental problem:
- Using the Launch Bar, build the selected project.
Expected: no error popup is shown and able to build the selected project.
Actual: An error popup displays the message "Change Build Configurations has encountered a problem". In the Build Console, the following message is shown: "Build not configured correctly". There is also an exception shown in the Error Log view:
java.lang.NullPointerException: Cannot invoke "org.eclipse.debug.core.ILaunchConfiguration.getAttribute(String, String)" because "launchConfig" is null
This happens in ISV code which attempts to access the launch config using:
ILaunchConfiguration launchConfig = getActiveLaunchConfiguration();
Analysis
When switching from project A to project B, the popup originates from the following logic:
|
private ICBuildConfiguration createCBuildConfig(IProject project, IToolChain toolChain, ILaunchTarget launchTarget, |
org.eclipse.cdt.internal.core.build.CBuildConfigurationManager.createCBuildConfig(IProject, IToolChain, ILaunchTarget, String, IProgressMonitor)
private ICBuildConfiguration createCBuildConfig(IProject project, IToolChain toolChain, ILaunchTarget launchTarget,
String launchMode, IProgressMonitor monitor) throws CoreException {
ICBuildConfiguration retVal = null;
ICBuildConfigurationProvider provider = getProvider(project);
if (provider != null) {
// The provider will call us back to add in the new one
retVal = provider.createCBuildConfiguration(project, toolChain, launchMode, launchTarget, monitor);
if (retVal != null) {
/*
* The IScannerInfoProvider may be cached with an incorrect value if the ICBuildConfiguration is not
* available at the time it is checked. Now that one has been created, the previous value should be
* forgotten so the new cconfig can be used.
*/
CCorePlugin.getDefault().resetCachedScannerInfoProvider(project);
return retVal;
}
throw new CoreException(
CCorePlugin.createStatus(String.format(Messages.CBuildConfigurationManager_CBuildConfigCreateFail,
project.getName(), toolChain.getName(), launchTarget.getId(), launchMode), null));
}
throw new CoreException(
CCorePlugin.createStatus(String.format(Messages.CBuildConfigurationManager_CBuildConfigProviderNotFound,
project.getName(), toolChain.getName(), launchTarget.getId(), launchMode), null));
}
retVal comes back null from provider.createCBuildConfiguration and so the first CoreException block above is executed.
This is caused by the ISV CMakeBuildConfigurationProvider.createCMakeBuildConfiguration(IBuildConfiguration, String, IToolChain, ICMakeToolChainFile, String, ILaunchTarget) method returning null. This happens because the passed ILaunchTarget is of the wrong type; it is the launch target for the other project type, so the ISV provider rejects it.
When the CoreBuildLaunchBarTracker handles the activeLaunchDescriptorChanged event, the descriptor has changed to the new type, but the other launch bar parameters - launch mode and launch target type - have not. Therefore things are out of sync.
When changing the Launch Bar project descriptor (middle dropdown, labelled Launch Configuration) to a new project which is of a different type, this problem may occur. The issue is always reproducible, but the conditions for reproduction are very specific.
I have reproduced the problem in an ISV extended CDT product, where there are multiple project types (natures) associated with different Launch Target types.
I have not tried to reproduce the problem in vanilla CDT.
When the problem occurs a Problem Occurred popup dialog appears containing the message
"Change Build Configurations has encountered a problem"
To reproduce (always):
Expected: no error popup is shown and able to build the selected project.
Actual: An error popup displays the message "Change Build Configurations has encountered a problem"
Supplemental problem:
Expected: no error popup is shown and able to build the selected project.
Actual: An error popup displays the message "Change Build Configurations has encountered a problem". In the Build Console, the following message is shown: "Build not configured correctly". There is also an exception shown in the Error Log view:
java.lang.NullPointerException: Cannot invoke "org.eclipse.debug.core.ILaunchConfiguration.getAttribute(String, String)" because "launchConfig" is nullThis happens in ISV code which attempts to access the launch config using:
ILaunchConfiguration launchConfig = getActiveLaunchConfiguration();Analysis
When switching from project A to project B, the popup originates from the following logic:
cdt/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/CBuildConfigurationManager.java
Line 336 in 04adc41
org.eclipse.cdt.internal.core.build.CBuildConfigurationManager.createCBuildConfig(IProject, IToolChain, ILaunchTarget, String, IProgressMonitor)
retVal comes back null from provider.createCBuildConfiguration and so the first CoreException block above is executed.
This is caused by the ISV CMakeBuildConfigurationProvider.createCMakeBuildConfiguration(IBuildConfiguration, String, IToolChain, ICMakeToolChainFile, String, ILaunchTarget) method returning null. This happens because the passed ILaunchTarget is of the wrong type; it is the launch target for the other project type, so the ISV provider rejects it.
When the CoreBuildLaunchBarTracker handles the activeLaunchDescriptorChanged event, the descriptor has changed to the new type, but the other launch bar parameters - launch mode and launch target type - have not. Therefore things are out of sync.