mengdiwang / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

NullPointerTester fails on @Nullable parameter without default value #510

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
For this test, I used the current SVN trunk (revision 144).

The attached test class reveals a potential problem with the NullPointerTester 
class: For a parameter that is @Nullable but has no configured default value in 
the NullPointerTester (e.g. a user defined class), the tester fails instead of 
just setting the parameter null.

I expect the NullPointerTester to use null for @Nullable parameters without a 
configured default value and pass the attached test case. Instead, I get an 
exception.

java.lang.RuntimeException: No default value found for 
com.google.common.testing.NullPointerTesterTest$NoDefaultValue
    at com.google.common.testing.Assert.fail(Assert.java:43)
    at com.google.common.testing.Assert.assertTrue(Assert.java:64)
    at com.google.common.testing.NullPointerTester.buildParamList(NullPointerTester.java:284)
    at com.google.common.testing.NullPointerTester.testFunctorParameter(NullPointerTester.java:249)
    at com.google.common.testing.NullPointerTester.testMethodParameter(NullPointerTester.java:194)
    at com.google.common.testing.NullPointerTester.testMethod(NullPointerTester.java:166)
    at com.google.common.testing.NullPointerTester.testAllPublicStaticMethods(NullPointerTester.java:137)
    at com.google.common.testing.NullPointerTesterTest.testBuildParameterList(NullPointerTesterTest.java:13)
...

I'm pretty sure the line NullPointerTester.java:283

if (!parameterIsPrimitiveOrNullable(func, indexOfParamToSetToNull)) {

should read

if (!parameterIsPrimitiveOrNullable(func, i)) {

Original issue reported on code.google.com by goo...@chsemrau.de on 29 Dec 2010 at 11:46

Attachments:

GoogleCodeExporter commented 9 years ago
I suppose it would be fair to use null as a backup default value for any 
nullable parameter.

Original comment by kevinb@google.com on 12 Jan 2011 at 9:01

GoogleCodeExporter commented 9 years ago

Original comment by kevinb@google.com on 12 Jan 2011 at 10:02

GoogleCodeExporter commented 9 years ago

Original comment by kevinb@google.com on 13 Jul 2011 at 6:18

GoogleCodeExporter commented 9 years ago

Original comment by fry@google.com on 16 Feb 2012 at 7:17

GoogleCodeExporter commented 9 years ago

Original comment by kevinb@google.com on 30 May 2012 at 7:41

GoogleCodeExporter commented 9 years ago

Original comment by kevinb@google.com on 30 May 2012 at 7:45

GoogleCodeExporter commented 9 years ago

Original comment by kevinb@google.com on 22 Jun 2012 at 6:16

GoogleCodeExporter commented 9 years ago

Original comment by kevinb@google.com on 22 Jun 2012 at 6:58

GoogleCodeExporter commented 9 years ago
This was fixed in 11.0, but we never updated the bug:

http://code.google.com/p/guava-libraries/source/detail?r=556976f81c236be7798e5d0
65a0dae09ca0cc1d3

We should add an explicit test for this if there isn't one already.

Original comment by cpov...@google.com on 22 Jun 2012 at 7:10

GoogleCodeExporter commented 9 years ago
Test added: 
http://code.google.com/p/guava-libraries/source/detail?r=8634dfafb850b8150c14de0
fc9c24cfcd05093cc

Sorry for the bug, the delay in fixing it, the lack of notification, and the 
failure to add a test.  Ugh.

Original comment by cpov...@google.com on 22 Jun 2012 at 8:09

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:09