Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 483836

Summary: Invalid potential null pointer access in casting variable
Product: [Eclipse Project] JDT Reporter: Marco Descher <marco>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: jarthana, stephan.herrmann
Version: 4.5.1   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X   
Whiteboard:

Description Marco Descher CLA 2015-12-07 14:04:54 EST
The following code gives me an invalid potential null pointer access at line 5:

1: ISelection selection = 
2:      HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
3: if (selection != null & selection instanceof IStructuredSelection) {
4: 	IStructuredSelection strucSelection = (IStructuredSelection) selection;
5: 	pat = (Patient) strucSelection.getFirstElement();
6: }

if I modify the code like this, the message is gone

1: ISelection selection = 
2:      HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
3: 	IStructuredSelection strucSelection = (IStructuredSelection) selection;
4: if (selection != null & selection instanceof IStructuredSelection) {
5: 	pat = (Patient) strucSelection.getFirstElement();
6: }
Comment 1 Marco Descher CLA 2015-12-08 01:12:28 EST
This solution also removes the npe warning

1: ISelection selection = 
2:     HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
3: 	IStructuredSelection strucSelection = (IStructuredSelection) selection;
4: if (selection instanceof IStructuredSelection) {
5: 	pat = (Patient) strucSelection.getFirstElement();
6: }
Comment 2 Jay Arthanareeswaran CLA 2015-12-08 01:20:28 EST
Stephan, can you comment on this please? Thanks!
Comment 3 Marco Descher CLA 2015-12-08 03:59:40 EST
I wrongly got a binary comparison (single &) instead of a full comparison (double &). Fixing this removes the error. So this is NOT INVALID!
Comment 4 Jay Arthanareeswaran CLA 2015-12-08 04:08:04 EST
(In reply to Marco Descher from comment #3)
> I wrongly got a binary comparison (single &) instead of a full comparison
> (double &). Fixing this removes the error. So this is NOT INVALID!

Did you mean NOT VALID?
Comment 5 Marco Descher CLA 2015-12-08 04:27:09 EST
yes :) or NOT NOT INVALID