[groovy-user] Weird Error in Groovy 1.6.2

4 views
Skip to first unread message

Dan Sline

unread,
Oct 1, 2009, 6:05:54 PM10/1/09
to us...@groovy.codehaus.org

All,

 

I’m getting a really weird error in Groovy 1.6.2.  For no reason at all it is giving me the following exception:

 

java.lang.NullPointerException: Cannot invoke method if() on null object

        at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77)

        at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:748)

        at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:725)

        at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:17)

        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:43)

        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)

        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:129)

 

 

Has anyone seen this error. This is happening sporadically, but when it happens, it is easily reproducible.  The funny thing is the object in the if statement is doing a null check on its own (and has a valid value).

 

Note:  I am forcing a System.gc as part of my process, so I don’t know if that could be causing part of the problem.

 

Any ideas?

 

Thanks,

Dan

 

 

Jochen Theodorou

unread,
Oct 1, 2009, 6:56:50 PM10/1/09
to us...@groovy.codehaus.org
Dan Sline schrieb:

>
> I’m getting a really weird error in Groovy 1.6.2. For no reason at all
> it is giving me the following exception:
>
>
> java.lang.NullPointerException: Cannot invoke method if() on null object
>
> at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77)
> at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:748)
> at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:725)
> at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:17)
> at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:43)
> at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
> at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:129)

wtf? this looks you are trying to do: null."if"()

> Has anyone seen this error. This is happening sporadically, but when it
> happens, it is easily reproducible. The funny thing is the object in
> the if statement is doing a null check on its own (and has a valid value).

I have never seen this.

bye blackdrag

--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Bob Brown

unread,
Oct 1, 2009, 7:01:04 PM10/1/09
to us...@groovy.codehaus.org
> I have never seen this.

I have...it's usually a typo...a 'dangling' period:

// groovy 1.7 console:
groovy> def x = null;
groovy> def y;
groovy> y = x.
groovy> if (x == y)
groovy> println "is null";

Exception thrown: Cannot invoke method if() on null object

java.lang.NullPointerException: Cannot invoke method if() on null object

at ConsoleScript3.run(ConsoleScript3:5)
//

Cheers,

BOB

Dan Sline

unread,
Oct 1, 2009, 7:55:14 PM10/1/09
to us...@groovy.codehaus.org
Bob,

Thanks. Your observation makes sense. However, the preceding line has a
method call that follows the standard syntax:

doSomething(x,y)

The code that is throwing the error looks something like this:
if( x != null) {
// .... perform logic here
}

The weird part about this logic is that it doesn't always throw an error in
the same block of code. If it always threw an error regardless which
scenario I run with, then I would think that there is either a problem with
my code or an issue with Groovy itself. However, this code doesn't always
throw an error.

Without compiling the class into Java class files, is there an easy way I
can see how Groovy is interpreting this code?

Thanks,
Dan

Reply all
Reply to author
Forward
0 new messages