commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Benedikt Ritter (JIRA)" <j...@apache.org>
Subject [jira] [Closed] (LANG-924) In FieldUtils replace Validate.isTrue(object != null) with Validate.notNull(object)
Date Fri, 18 Oct 2013 12:20:42 GMT

     [ https://issues.apache.org/jira/browse/LANG-924?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Benedikt Ritter closed LANG-924.
--------------------------------

    Resolution: Invalid

Changing this in not a good idea on second thought because it will produce stack traces like:

{code}
java.lang.NullPointerException: Cannot locate declared field class org.apache.commons.lang3.reflect.testbed.PublicChild.s
	at org.apache.commons.lang3.Validate.notNull(Validate.java:222)
	at org.apache.commons.lang3.reflect.FieldUtils.readDeclaredField(FieldUtils.java:475)
	at org.apache.commons.lang3.reflect.FieldUtils.readDeclaredField(FieldUtils.java:450)
	at org.apache.commons.lang3.reflect.FieldUtilsTest.testReadDeclaredNamedField(FieldUtilsTest.java:653)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
{code}

> In FieldUtils replace Validate.isTrue(object != null) with Validate.notNull(object)
> -----------------------------------------------------------------------------------
>
>                 Key: LANG-924
>                 URL: https://issues.apache.org/jira/browse/LANG-924
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.reflect.*
>    Affects Versions: 3.1
>            Reporter: Benedikt Ritter
>             Fix For: Review Patch
>
>
> Methods in FieldUtils validate input using code like:
> {code}
> Validate.isTrue(cls != null, "The class must not be null")
> {code}
> This could be changed to:
> {code}
> Validate.notNull(cls, "The class must not be null")
> {code}
> However this could affect client code, since isTrue(boolean) throws IllegalArgumentException
and notNull throws NullPointerException.



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Mime
View raw message