This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 222795 - Ability to suppress "null pointer dereference" hint
Summary: Ability to suppress "null pointer dereference" hint
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 7.3
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Jan Lahoda
URL:
Keywords:
Depends on: 224988
Blocks:
  Show dependency tree
 
Reported: 2012-11-27 00:19 UTC by _ gtzabari
Modified: 2013-01-16 19:09 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description _ gtzabari 2012-11-27 00:19:04 UTC
We should be able to suppress this warning. My use-case:

1. The database returns a non-null department object. The department has a foreign key: companyId. I know the company is non-null because I am using REPEATABLE_READ transaction isolation level so if the department exists, the company must exist as well.
2. I look up the company in the database and try to dereference its fields.
3. I assert(company!=null) just in case but Netbeans ignores this.
4. Netbeans complains "null pointer dereference"

Expected behavior:
1. assert() should count as a null pointer check
2. Ability to suppress the null pointer dereference warning using @SupressWarnings
Comment 1 Quality Engineering 2012-11-28 02:36:00 UTC
Integrated into 'main-golden', will be available in build *201211280002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/1f813511384a
User: Jan Lahoda <jlahoda@netbeans.org>
Log: #222795: support for assert.
Comment 2 Jan Lahoda 2012-11-30 18:10:05 UTC
Thank for the testcase - added a @SuppressWarnings key and support for assert.
Comment 3 _ gtzabari 2013-01-15 20:14:54 UTC
Reopening because assert() no longer suppresses this hint as of:

Product Version: NetBeans IDE Dev (Build 201301120001)
Java: 1.7.0_11; Java HotSpot(TM) 64-Bit Server VM 23.6-b04
Runtime: Java(TM) SE Runtime Environment 1.7.0_11-b21
System: Windows 7 version 6.1 running on amd64; Cp1252; en_CA (nb)
User directory: C:\Users\Gili\AppData\Roaming\NetBeans\dev
Cache directory: C:\Users\Gili\AppData\Local\NetBeans\Cache\dev

Here is my code:

public class Test extends GuiceServletContextListener
{
	@Nullable
	private Injector injector;

	@Override
	protected Injector getInjector()
	{
		assert (this.injector == null): injector;
		this.injector = Guice.createInjector(new JerseyModule());
		return injector;
	}

	@Override
	public void contextInitialized(ServletContextEvent servletContextEvent)
	{
		assert (injector != null);
		String test = injector.getInstance(String.class);
		super.contextInitialized(servletContextEvent);
	}
}

In the line "String test = ..." injector is flagged as dereferencing null.
Comment 4 Jan Lahoda 2013-01-16 19:09:47 UTC
I filed a separate bug #224988 for that to simplify adding the fix into a patch release (or to the 7.3 itself if approved).