Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -783,11 +783,15 @@ public void modifyText(ModifyEvent e)
private String getLaunchTarget()
{
launchBarManager = Activator.getService(ILaunchBarManager.class);
String selectedTarget = ""; //$NON-NLS-1$
String selectedTarget = StringUtil.EMPTY;
try
{
selectedTarget = launchBarManager.getActiveLaunchTarget().getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET,
""); //$NON-NLS-1$
if (launchBarManager.getActiveLaunchConfiguration() != null)
{
selectedTarget = launchBarManager.getActiveLaunchTarget()
.getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY);
}

Comment on lines +786 to +794
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null check for launchBarManager.getActiveLaunchConfiguration() is good for preventing Null Pointer Exceptions. However, it would be better to also check if launchBarManager.getActiveLaunchTarget() is not null before calling getAttribute on it. This will further enhance the robustness of the code.

- if (launchBarManager.getActiveLaunchConfiguration() != null)
+ if (launchBarManager.getActiveLaunchConfiguration() != null && launchBarManager.getActiveLaunchTarget() != null)

Commitable suggestion

[!IMPORTANT]
Carefully review the code before committing. Make sure it correctly replaces the highlighted code, has no missing lines and indentaion issues.

Suggested change
String selectedTarget = StringUtil.EMPTY;
try
{
selectedTarget = launchBarManager.getActiveLaunchTarget().getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET,
""); //$NON-NLS-1$
if (launchBarManager.getActiveLaunchConfiguration() != null)
{
selectedTarget = launchBarManager.getActiveLaunchTarget()
.getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY);
}
String selectedTarget = StringUtil.EMPTY;
try
{
if (launchBarManager.getActiveLaunchConfiguration() != null && launchBarManager.getActiveLaunchTarget() != null)
{
selectedTarget = launchBarManager.getActiveLaunchTarget()
.getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY);
}

}
catch (CoreException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected void initializeProgramName(ICElement cElement, ILaunchConfigurationWor
IProject project = cElement.getCProject().getProject();
String name = project.getName();
ICProjectDescription projDes = CCorePlugin.getDefault().getProjectDescription(project);
if (projDes != null)
if (projDes != null && projDes.getActiveConfiguration() != null)
{
String buildConfigName = projDes.getActiveConfiguration().getName();
name = name + " " + buildConfigName; //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,9 @@ public void widgetSelected(SelectionEvent evt) {

Optional<String> suitableTarget = Stream.of(targetsWithDfuSupport).filter(t -> {
try {
return t.contentEquals(launchBarManager.getActiveLaunchTarget().getId());
if (launchBarManager.getActiveLaunchConfiguration() != null) {
return t.contentEquals(launchBarManager.getActiveLaunchTarget().getId());
}
Comment on lines +311 to +313
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null check for getActiveLaunchConfiguration() is good for preventing NullPointerExceptions. However, consider storing the result of getActiveLaunchTarget() in a local variable to avoid calling it twice, which could potentially improve performance.

- if (launchBarManager.getActiveLaunchConfiguration() != null) {
-     return t.contentEquals(launchBarManager.getActiveLaunchTarget().getId());
- }
+ LaunchTarget activeLaunchTarget = launchBarManager.getActiveLaunchTarget();
+ if (activeLaunchTarget != null) {
+     return t.contentEquals(activeLaunchTarget.getId());
+ }

Commitable suggestion

[!IMPORTANT]
Carefully review the code before committing. Make sure it correctly replaces the highlighted code, has no missing lines and indentaion issues.

Suggested change
if (launchBarManager.getActiveLaunchConfiguration() != null) {
return t.contentEquals(launchBarManager.getActiveLaunchTarget().getId());
}
LaunchTarget activeLaunchTarget = launchBarManager.getActiveLaunchTarget();
if (activeLaunchTarget != null) {
return t.contentEquals(activeLaunchTarget.getId());
}

} catch (CoreException e) {
Logger.log(e);
}
Expand Down Expand Up @@ -490,7 +492,7 @@ protected void initializeCProject(IProject project, ILaunchConfigurationWorkingC
config.setMappedResources(new IResource[] { project });

ICProjectDescription projDes = CCorePlugin.getDefault().getProjectDescription(project);
if (projDes != null) {
if (projDes != null && projDes.getActiveConfiguration() != null) {
String buildConfigID = projDes.getActiveConfiguration().getId();
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_BUILD_CONFIG_ID, buildConfigID);
}
Expand Down Expand Up @@ -803,8 +805,10 @@ private String newVariableExpression(OpenocdDynamicVariable dynamicVariable) {
private String getLaunchTarget() {
String selectedTarget = StringUtil.EMPTY;
try {
selectedTarget = launchBarManager.getActiveLaunchTarget().getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET,
StringUtil.EMPTY);
if (launchBarManager.getActiveLaunchConfiguration() != null) {
selectedTarget = launchBarManager.getActiveLaunchTarget()
.getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY);
}
Comment on lines +808 to +811
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the first comment, consider storing the result of getActiveLaunchTarget() in a local variable to avoid calling it twice.

- if (launchBarManager.getActiveLaunchConfiguration() != null) {
-     selectedTarget = launchBarManager.getActiveLaunchTarget()
-             .getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY);
- }
+ LaunchTarget activeLaunchTarget = launchBarManager.getActiveLaunchTarget();
+ if (activeLaunchTarget != null) {
+     selectedTarget = activeLaunchTarget.getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY);
+ }

Commitable suggestion

[!IMPORTANT]
Carefully review the code before committing. Make sure it correctly replaces the highlighted code, has no missing lines and indentaion issues.

Suggested change
if (launchBarManager.getActiveLaunchConfiguration() != null) {
selectedTarget = launchBarManager.getActiveLaunchTarget()
.getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY);
}
LaunchTarget activeLaunchTarget = launchBarManager.getActiveLaunchTarget();
if (activeLaunchTarget != null) {
selectedTarget = activeLaunchTarget.getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY);
}

} catch (CoreException e) {
Logger.log(e);
}
Expand Down