Skip to content

Commit 0a7eae5

Browse files
committed
cross.packs: Docs NPE fixed
1 parent b935ecb commit 0a7eae5

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

ilg.gnuarmeclipse.core/src/ilg/gnuarmeclipse/core/EclipseUtils.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
* >Eclipse Wiki</a>.
6969
*
7070
*/
71+
@SuppressWarnings("restriction")
7172
public class EclipseUtils {
7273

7374
// ------------------------------------------------------------------------
@@ -157,10 +158,13 @@ public static IProject getSelectedProject() {
157158
IWorkbenchWindow window = PlatformUI.getWorkbench()
158159
.getActiveWorkbenchWindow();
159160
if (window != null) {
160-
IStructuredSelection selection = (IStructuredSelection) window
161-
.getSelectionService().getSelection();
162-
if ((selection != null) && (selection.size() == 1)) {
163-
Object firstElement = selection.getFirstElement();
161+
162+
Object selection = window.getSelectionService().getSelection();
163+
if ((selection != null)
164+
&& (selection instanceof IStructuredSelection)
165+
&& (((IStructuredSelection) selection).size() == 1)) {
166+
Object firstElement = ((IStructuredSelection) selection)
167+
.getFirstElement();
164168
if (firstElement instanceof IAdaptable) {
165169
IProject project = (IProject) ((IAdaptable) firstElement)
166170
.getAdapter(IProject.class);
@@ -234,7 +238,6 @@ public static void ClearStatusMessage() {
234238

235239
Display.getDefault().syncExec(new Runnable() {
236240

237-
@SuppressWarnings("restriction")
238241
public void run() {
239242
IWorkbenchWindow window = PlatformUI.getWorkbench()
240243
.getActiveWorkbenchWindow();
@@ -259,7 +262,6 @@ public static void showStatusMessage(final String message) {
259262
System.out.println(message);
260263
Display.getDefault().syncExec(new Runnable() {
261264

262-
@SuppressWarnings("restriction")
263265
public void run() {
264266
IWorkbenchWindow window = PlatformUI.getWorkbench()
265267
.getActiveWorkbenchWindow();
@@ -276,7 +278,6 @@ public static void showStatusErrorMessage(final String message) {
276278
System.out.println(message);
277279
Display.getDefault().syncExec(new Runnable() {
278280

279-
@SuppressWarnings("restriction")
280281
public void run() {
281282
IWorkbenchWindow window = PlatformUI.getWorkbench()
282283
.getActiveWorkbenchWindow();

0 commit comments

Comments
 (0)