Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IEP-1110 NPE when trying to create new launch configuration #852

Merged
merged 2 commits into from
Nov 15, 2023

Conversation

sigmaaa
Copy link
Collaborator

@sigmaaa sigmaaa commented Nov 8, 2023

Description

To reproduce: create project -> build project -> Close project -> try to create new Launch Config -> get error -> close window -> restart -> try to create new Launch Config -> get error -> restart -> try to create new Launch Config -> get error -> Open Project -> try to create new Launch Config -> get error:

Fixes # (IEP-1110)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How has this been tested?

Test 1:

  • verified steps mentioned in the description

Test Configuration:

  • ESP-IDF Version:
  • OS (Windows,Linux and macOS):

Dependent components impacted by this PR:

  • Launch configuration
  • Debug configuration

Checklist

  • PR Self Reviewed
  • Applied Code formatting
  • Added Documentation
  • Added Unit Test
  • Verified on all platforms - Windows,Linux and macOS

Summary by CodeRabbit

  • Bug Fixes
    • Improved robustness of the application by adding conditional checks to prevent potential null pointer exceptions when accessing active launch configurations and targets.
    • Enhanced stability by ensuring active project configuration is not null before appending its name to the project name.

Copy link

coderabbitai bot commented Nov 8, 2023

Walkthrough

The changes primarily focus on enhancing the robustness of the code in various Java classes within the com.espressif.idf bundle. This is achieved by introducing conditional checks to prevent potential null pointer exceptions when accessing the active launch configuration or target.

Changes

File Path Change Summary
.../idf/debug/gdbjtag/openocd/ui/TabDebugger.java Updated getLaunchTarget method to include a null check before accessing selectedTarget attribute.
.../idf/launch/serial/ui/internal/CMakeMainTab2.java Added null checks in widgetSelected, initializeCProject, and getLaunchTarget methods to handle null ActiveLaunchConfiguration.
.../idf/debug/gdbjtag/openocd/ui/TabMain.java Introduced a null check before appending the active configuration's name to the project name.

Poem

🍂 As the leaves fall, the code stands tall, 🍁
No more nulls to make it fall. 🐇
On this day, in history's hall, 📜
The Berlin Wall began to fall. 🏰
Just like that, without a brawl, 🕊️
We've made our code a safer hall. 🛡️
So let's celebrate, one and all, 🎉
With hot cocoa, in the chilly fall. ☕


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai help to get help.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 05ea8a4 and 6b8021c.
Files selected for processing (2)
  • bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/TabDebugger.java (1 hunks)
  • bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/CMakeMainTab2.java (2 hunks)

Comment on lines +786 to +794
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);
}

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);
}

@AndriiFilippov
Copy link
Collaborator

@sigmaaa hi !

Tested under:
OS - Windows 10
ESP-IDF: v5.1.1

Test 1: 1) Close project -> try to create new Launch Config -> get error -> close window -> restart -> try to create new Launch Config -> clear error message. 👍

Test 2: create project -> build project -> Close project -> try to create new Launch Config -> get error -> close window -> restart -> try to create new Launch Config -> get error -> restart -> try to create new Launch Config -> get error -> Open Project -> try to create new Launch Config -> get error: STILL PERSIST.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6b8021c and 9c64dea.
Files selected for processing (2)
  • bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/TabMain.java (1 hunks)
  • bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/CMakeMainTab2.java (3 hunks)
Additional comments: 2
bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/TabMain.java (1)
  • 78-84: The null check for projDes and projDes.getActiveConfiguration() is a good practice to prevent potential Null Pointer Exceptions. This change enhances the robustness of the code.
bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/CMakeMainTab2.java (1)
  • 495-498: The null checks for projDes and projDes.getActiveConfiguration() are good for preventing NullPointerExceptions. No changes needed.

Comment on lines +311 to +313
if (launchBarManager.getActiveLaunchConfiguration() != null) {
return t.contentEquals(launchBarManager.getActiveLaunchTarget().getId());
}
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());
}

Comment on lines +808 to +811
if (launchBarManager.getActiveLaunchConfiguration() != null) {
selectedTarget = launchBarManager.getActiveLaunchTarget()
.getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY);
}
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);
}

@sigmaaa
Copy link
Collaborator Author

sigmaaa commented Nov 8, 2023

@sigmaaa hi !

Tested under: OS - Windows 10 ESP-IDF: v5.1.1

Test 1: 1) Close project -> try to create new Launch Config -> get error -> close window -> restart -> try to create new Launch Config -> clear error message. 👍

Test 2: create project -> build project -> Close project -> try to create new Launch Config -> get error -> close window -> restart -> try to create new Launch Config -> get error -> restart -> try to create new Launch Config -> get error -> Open Project -> try to create new Launch Config -> get error: STILL PERSIST.

Hi @AndriiFilippov, pushed a commit, which should fix the test 2

@AndriiFilippov
Copy link
Collaborator

@sigmaaa hi !

Test 2: create project -> build project -> Close project -> try to create new Launch Config -> get error -> close window -> restart -> try to create new Launch Config -> get error -> restart -> try to create new Launch Config -> get error -> Open Project -> try to create new Launch Config -> click "Cancel" -> Launch Bar settings disappear.
|
image

@AndriiFilippov
Copy link
Collaborator

@sigmaaa, tested.

LGTM 👍

@kolipakakondal kolipakakondal added this to the v2.12.0 milestone Nov 15, 2023
Copy link
Collaborator

@kolipakakondal kolipakakondal left a comment

Choose a reason for hiding this comment

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

LGTM

@kolipakakondal kolipakakondal merged commit 0a16bbb into master Nov 15, 2023
7 checks passed
@kolipakakondal kolipakakondal deleted the IEP-1110 branch November 15, 2023 06:37
Copy link
Collaborator Author

@sigmaaa sigmaaa left a comment

Choose a reason for hiding this comment

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

self reviewed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants