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-1268: Welcome page closed when opening ESP-IDF Manager #1005

Merged
merged 1 commit into from
Jul 3, 2024
Merged
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 @@ -10,16 +10,17 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.part.ViewPart;

import com.espressif.idf.core.logging.Logger;
import com.espressif.idf.core.tools.IToolsInstallationWizardConstants;
import com.espressif.idf.ui.handlers.EclipseHandler;
import com.espressif.idf.ui.tools.manager.ESPIDFManagerEditor;


public class ManageEspIdfVersionsHandler extends AbstractHandler
{

Expand All @@ -29,7 +30,7 @@
launchEditor();
return null;
}

private void launchEditor()
{
Display.getDefault().asyncExec(new Runnable()
Expand All @@ -38,17 +39,31 @@
public void run()
{
IWorkbenchWindow activeww = EclipseHandler.getActiveWorkbenchWindow();
if (activeww != null)
{
IWorkbenchPage page = activeww.getActivePage();
if (page != null)
{
ViewPart viewPart = (ViewPart) page.findView("org.eclipse.ui.internal.introview");
if (viewPart != null)
{
page.hideView(viewPart);
}
Comment on lines +47 to +51
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: ViewPart casting is not necessary here. We can use IViewPart instead of ViewPart. Also, we don't need if (viewPart != null), because it's a part of the page.hideView(IViewPart) method.


}
}
Comment on lines +42 to +54
Copy link

Choose a reason for hiding this comment

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

Ensure robustness in UI manipulation.

The logic to hide the welcome page is implemented correctly. However, consider adding a type check before casting the view to ViewPart to avoid potential ClassCastException.

- ViewPart viewPart = (ViewPart) page.findView("org.eclipse.ui.internal.introview");
+ IViewPart viewPart = page.findView("org.eclipse.ui.internal.introview");
+ if (viewPart instanceof ViewPart) {
+     page.hideView((ViewPart)viewPart);
+ }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (activeww != null)
{
IWorkbenchPage page = activeww.getActivePage();
if (page != null)
{
ViewPart viewPart = (ViewPart) page.findView("org.eclipse.ui.internal.introview");
if (viewPart != null)
{
page.hideView(viewPart);
}
}
}
if (activeww != null)
{
IWorkbenchPage page = activeww.getActivePage();
if (page != null)
{
IViewPart viewPart = page.findView("org.eclipse.ui.internal.introview");
if (viewPart instanceof ViewPart)
{
page.hideView((ViewPart)viewPart);
}
}
}

try
{
File inputFile = new File(toolSetConfigFilePath());
if (!inputFile.exists())
{
inputFile.createNewFile();

Check warning on line 60 in bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/ManageEspIdfVersionsHandler.java

View workflow job for this annotation

GitHub Actions / spotbugs

RV_RETURN_VALUE_IGNORED_BAD_PRACTICE

Exceptional return value of java.io.File.createNewFile() ignored in com.espressif.idf.ui.tools.ManageEspIdfVersionsHandler$1.run()
Raw output
This method returns a value that is not checked. The return value should be checked since it can indicate an unusual or unexpected function execution. For example, the File.delete() method returns false if the file could not be successfully deleted (rather than throwing an Exception). If you don't check the result, you won't notice if the method invocation signals unexpected behavior by returning an atypical return value.
}

IFile iFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(inputFile.getAbsolutePath()));


IFile iFile = ResourcesPlugin.getWorkspace().getRoot()
.getFile(new Path(inputFile.getAbsolutePath()));

IDE.openEditor(activeww.getActivePage(), new FileEditorInput(iFile), ESPIDFManagerEditor.EDITOR_ID);

Check warning on line 66 in bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/ManageEspIdfVersionsHandler.java

View workflow job for this annotation

GitHub Actions / spotbugs

NP_NULL_ON_SOME_PATH

Possible null pointer dereference of activeww in com.espressif.idf.ui.tools.ManageEspIdfVersionsHandler$1.run()
Raw output
There is a branch of statement that, if executed, guarantees that a null value will be dereferenced, which would generate a NullPointerException when the code is executed. Of course, the problem might be that the branch or statement is infeasible and that the null pointer exception cannot ever be executed; deciding that is beyond the ability of SpotBugs.
}
catch (Exception e)
{
Expand All @@ -57,7 +72,7 @@
}
});
}

private String toolSetConfigFilePath()
{
IPath path = ResourcesPlugin.getWorkspace().getRoot().getLocation();
Expand Down
Loading