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

XpackUtils throwing a NPE when calling System Repo Base Paths #549

Closed
vishnusarathashling opened this issue Feb 2, 2023 · 13 comments
Closed
Milestone

Comments

@vishnusarathashling
Copy link
Contributor

Description

XpackUtils throwing a NPE when calling System Repo Base Paths. When trying to create a new project from the Wizard, there is an NPE received in the last (toolchain selection) page. Please see the detailed log below.

java.lang.NullPointerException: Cannot invoke "String.indexOf(int)" because "fullPath" is null at org.eclipse.core.runtime.Path.<init>(Path.java:231) at org.eclipse.core.runtime.Path.<init>(Path.java:189) at org.eclipse.embedcdt.core.XpackUtils.getSysRepoBasePaths(XpackUtils.java:130) at org.eclipse.embedcdt.core.XpackUtils.getSysRepoPath(XpackUtils.java:185) at org.eclipse.embedcdt.core.XpackUtils.getSysPackPath(XpackUtils.java:209) at org.eclipse.embedcdt.core.XpackUtils.getPackVersions(XpackUtils.java:253) at org.eclipse.embedcdt.ui.XpackDirectoryNotStrictFieldEditor.<init>(XpackDirectoryNotStrictFieldEditor.java:41) at org.eclipse.embedcdt.internal.managedbuild.cross.riscv.ui.preferences.GlobalToolchainsPathsPreferencesPage.createFieldEditors(GlobalToolchainsPathsPreferencesPage.java:177) at org.eclipse.jface.preference.FieldEditorPreferencePage.createContents(FieldEditorPreferencePage.java:227) at org.eclipse.jface.preference.PreferencePage.createControl(PreferencePage.java:244) at org.eclipse.jface.preference.PreferenceDialog.createPageControl(PreferenceDialog.java:1433) at org.eclipse.jface.preference.PreferenceDialog$8.run(PreferenceDialog.java:1196) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45) at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:174) at org.eclipse.jface.preference.PreferenceDialog.showPage(PreferenceDialog.java:1188) at org.eclipse.ui.internal.dialogs.FilteredPreferenceDialog.showPage(FilteredPreferenceDialog.java:630) at org.eclipse.jface.preference.PreferenceDialog$5.lambda$0(PreferenceDialog.java:660) at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:74) at org.eclipse.jface.preference.PreferenceDialog$5.selectionChanged(PreferenceDialog.java:657) at org.eclipse.jface.viewers.StructuredViewer$3.run(StructuredViewer.java:821) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45) at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:174) at org.eclipse.jface.viewers.StructuredViewer.firePostSelectionChanged(StructuredViewer.java:818) at org.eclipse.jface.viewers.StructuredViewer.handlePostSelect(StructuredViewer.java:1191) at org.eclipse.swt.events.SelectionListener$1.widgetSelected(SelectionListener.java:84) at org.eclipse.jface.util.OpenStrategy.firePostSelectionEvent(OpenStrategy.java:284) at org.eclipse.jface.util.OpenStrategy$1.lambda$1(OpenStrategy.java:438) at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:40) at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:185) at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4035) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3635) at org.eclipse.jface.window.Window.runEventLoop(Window.java:823) at org.eclipse.jface.window.Window.open(Window.java:799) at org.eclipse.ui.internal.OpenPreferencesAction.run(OpenPreferencesAction.java:66) at org.eclipse.jface.action.Action.runWithEvent(Action.java:474) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:580) at org.eclipse.jface.action.ActionContributionItem.lambda$4(ActionContributionItem.java:414) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89) at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4243) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1063) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4060) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3632) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1155) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1046) at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:155) at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:644) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:551) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:156) at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:152) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:136) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:401) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) at java.base/java.lang.reflect.Method.invoke(Method.java:578) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:659) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:596) at org.eclipse.equinox.launcher.Main.run(Main.java:1467) at org.eclipse.equinox.launcher.Main.main(Main.java:1440)

@vishnusarathashling
Copy link
Contributor Author

Just adding some more points:

  • The issue seems to be because we are using non-capital key from the env map in XpackUtils::getSysRepoBasePaths if the platform is windows.
  • If I am changing the key from "ProgramFiles" to "PROGRAMFILES" this seems to be working with any exception.
  • I see that we are accessing using caps key in all other functions. I am not sure whether we have any specific reason here to use a non-caps key.

@ilg-ul Please share your valuable thoughts on this.

@ilg-ul
Copy link
Contributor

ilg-ul commented Feb 2, 2023

The NPE is definitely a bug, but I have difficulties to understand the context.

Can you provide a detailed sequence of steps to reproduce the error?

@vishnusarathashling
Copy link
Contributor Author

Steps to Reproduce:

  • Create a new C Managed Project.
  • Select Executable->Hello World RISC-V Project. Toolchains panel select RISC-V Cross GCC. Click Next button.
  • Select valid values in the next Page (Basic Settings).Click Next button.
  • In the next page "Select Cofigurations" both Debug and Release are selected.
  • Clicking on Next button from here causes NPE internally and the page is not changing.

Background: The toolchain mentioned in default preference is 2262347901(RISC-V GCC/Newlib).

We haven't set any default preference for toolchain.xpack.names.2262347901. So the fXpackNames returned from this call : fDefaultPreferences.getToolchainXpackNames(fSelectedToolchainId, fSelectedToolchainName) (line 175 of SetCrossCommandWizardPage) will be an array with 1 value as an empty string. With this array a call is made to XpackUtils::getPackVersions which eventually calls to getSysRepoPath().

@vishnusarathashling
Copy link
Contributor Author

It seems like if we are using System.getenv("ProgramFiles") it would return the correct value. The call to System.getenv is case insensitive and the map returned by System.getenv() is case sensitive (as per the documentation). When I tried using System.getenv("ProgramFiles") directly it's working fine. Just adding the behaviour which I saw.

@ilg-ul
Copy link
Contributor

ilg-ul commented Feb 3, 2023

It seems like if we are using System.getenv("ProgramFiles") it would return the correct value. ...

What is the context of this statement? How is it related to the NPE?

@ilg-ul
Copy link
Contributor

ilg-ul commented Feb 3, 2023

Steps to Reproduce: ...

What OS and what versions of Eclipse/plug-ins?

@vishnusarathashling
Copy link
Contributor Author

vishnusarathashling commented Feb 3, 2023

It seems like if we are using System.getenv("ProgramFiles") it would return the correct value. ...

What is the context of this statement? How is it related to the NPE?

I am using Windows 10 machine. I tried debugging and found like we have a call to System.getenv() in XpackUtils::getSysRepoBasePaths. The System.getenv() call give a map which has all keys in UPPER CASE. And because of which env.get("ProgramFiles") is returning null and finally resulting in the NPE when passed to org.eclipse.core.runtime.Path constructor. So I think if we try to fetch the "ProgramFiles" variable using System.getenv("ProgramFiles") it will be giving the correct path (since this call is case insensitive).

@vishnusarathashling
Copy link
Contributor Author

vishnusarathashling commented Feb 3, 2023

Steps to Reproduce: ...

What OS and what versions of Eclipse/plug-ins?

Please see the below versions of the platform.
OS: Windows 10.
Eclipse : 2022-09
CDT : 10.7.1
Embed CDT : 6.3.1

@ilg-ul
Copy link
Contributor

ilg-ul commented Feb 3, 2023

I think if we try to fetch the "ProgramFiles" variable using System.getenv("ProgramFiles") it will be giving the correct path (since this call is case insensitive).

Could you prepare a pull request (based on the develop branch) with a version that works in your environment?

@vishnusarathashling
Copy link
Contributor Author

I think if we try to fetch the "ProgramFiles" variable using System.getenv("ProgramFiles") it will be giving the correct path (since this call is case insensitive).

Could you prepare a pull request (based on the develop branch) with a version that works in your environment?

Sure I will do that.

vishnusarathashling added a commit to vishnusarathashling/eclipse-plugins that referenced this issue Feb 3, 2023
@vishnusarathashling
Copy link
Contributor Author

Done : #550. @ilg-ul Please have a look.

ilg-ul added a commit that referenced this issue Feb 3, 2023
[#549] Fix NPE in XpackUtils::getSysRepoBasePaths
@ilg-ul
Copy link
Contributor

ilg-ul commented Feb 3, 2023

Merged, thank you.

I'll make a new release during the next few days.

@ilg-ul ilg-ul closed this as completed Feb 3, 2023
@vishnusarathashling
Copy link
Contributor Author

Thanks @ilg-ul.

@ilg-ul ilg-ul added this to the 6.3.2 milestone Feb 6, 2023
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

No branches or pull requests

2 participants