You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by OCsite <oc...@ocs.cz> on 2020/06/05 11:33:18 UTC

Re: do I miss something here, or is this a Groovy bug?

And another thing which I don't understand and seems highly suspicious — do I just miss something of importance, or is it a bug?

===
127 ocs /tmp> <q.groovy 
class q {
  static main(av) {
    println "my MC is $this.metaClass"
  }
}
128 ocs /tmp> /usr/local/groovy-3.0.4/bin/groovy q
Caught: java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    q.main([Ljava/lang/String;)V @21: getfield
  Reason:
    Type '[Ljava/lang/String;' (current frame, stack[7]) is not assignable to 'q'
  Current Frame:
    bci: @21
    flags: { }
    locals: { '[Ljava/lang/String;', '[Lorg/codehaus/groovy/runtime/callsite/CallSite;' }
    stack: { 'org/codehaus/groovy/runtime/callsite/CallSite', 'java/lang/Class', uninitialized 10, uninitialized 10, '[Ljava/lang/Object;', '[Ljava/lang/Object;', integer, '[Ljava/lang/String;' }
  Bytecode:
    0000000: b800 144c 2b12 2132 1202 bb00 2359 04bd
    0000010: 0004 5903 2ab4 001c 5305 bd00 2559 0312
    0000020: 2753 5904 1229 53b7 002c b900 3203 0057
    0000030: b1                                     

java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    q.main([Ljava/lang/String;)V @21: getfield
  Reason:
    Type '[Ljava/lang/String;' (current frame, stack[7]) is not assignable to 'q'
  Current Frame:
    bci: @21
    flags: { }
    locals: { '[Ljava/lang/String;', '[Lorg/codehaus/groovy/runtime/callsite/CallSite;' }
    stack: { 'org/codehaus/groovy/runtime/callsite/CallSite', 'java/lang/Class', uninitialized 10, uninitialized 10, '[Ljava/lang/Object;', '[Ljava/lang/Object;', integer, '[Ljava/lang/String;' }
  Bytecode:
    0000000: b800 144c 2b12 2132 1202 bb00 2359 04bd
    0000010: 0004 5903 2ab4 001c 5305 bd00 2559 0312
    0000020: 2753 5904 1229 53b7 002c b900 3203 0057
    0000030: b1                                     

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
129 ocs /tmp> 
===

> On 27 May 2020, at 23:42, ocs@ocs.cz wrote:
> 
> 484 ocs /tmp> <q.groovy 
> class q {
>  static main(av) {
>    new Foo().test()
>  }
> }
> class Foo extends Root { }
> class Root {
>    private _objects=[]
>    void test() {
>        println "this is OK"
>        _objects<<'hi'
>        println "this crashes"
>        1.times { _objects<<it }
>    }
> }
> 485 ocs /tmp> /usr/local/groovy-3.0.4/bin/groovy q
> this is OK
> this crashes
> Caught: groovy.lang.MissingPropertyException: No such property: _objects for class: Foo
> groovy.lang.MissingPropertyException: No such property: _objects for class: Foo
> 	at Root$_test_closure1.doCall(q.groovy:13)
> 	at Root.test(q.groovy:13)
> 	at Root$test.call(Unknown Source)
> 	at q.main(q.groovy:3)
> 486 ocs /tmp> 
> 


Re: do I miss something here, or is this a Groovy bug?

Posted by OCsite <oc...@ocs.cz>.
Paul,

> On 5 Jun 2020, at 15:11, Paul King <pa...@asert.com.au> wrote:
> We should never throw a VerifyError, so that is a bug.

OK, I'll create an issue for that, or will you? (I guess you'd be able to describe it much better than me.)

> But you probably don't want to use "this" in a static context. You probably just want $q.metaClass or ${getMetaClass()}.

Well they do work, but I believe Groovy, unlike Java, should support static this properly, thus in a q's static method q.whatever and this.whatever should be always precisely the same[1]. And for readability and robustness (e.g., when the code is copied to another class), I would strongly prefer the latter.

Am I wrong, do I miss something here?

And as for the other issue

> You can make _objects protected to overcome the MPE or use a local variable, e.g.:
>         def localVar = _objects
>         1.times { localVar << it }

Thanks, of both these work-arounds I happen to know; my question is whether the problem with private fields is the intended behaviour (in which case I must admit I have missed it in closure documentation), or whether it is a bug which I should report :)

Thanks a lot!
OC

[1] Agreed, using this might lead someone who is used to an object-oriented language like Ruby or Smalltalk to believe that it would work properly when inherited, but it would not, for Java's at best half-OO, half-C++-like-crap. But that's beside the point here :)

> 
> Cheers, Paul.
> 
> 
> On Fri, Jun 5, 2020 at 9:33 PM OCsite <ocs@ocs.cz <ma...@ocs.cz>> wrote:
> And another thing which I don't understand and seems highly suspicious — do I just miss something of importance, or is it a bug?
> 
> ===
> 127 ocs /tmp> <q.groovy 
> class q {
>   static main(av) {
>     println "my MC is $this.metaClass"
>   }
> }
> 128 ocs /tmp> /usr/local/groovy-3.0.4/bin/groovy q
> Caught: java.lang.VerifyError: Bad type on operand stack
> Exception Details:
>   Location:
>     q.main([Ljava/lang/String;)V @21: getfield
>   Reason:
>     Type '[Ljava/lang/String;' (current frame, stack[7]) is not assignable to 'q'
>   Current Frame:
>     bci: @21
>     flags: { }
>     locals: { '[Ljava/lang/String;', '[Lorg/codehaus/groovy/runtime/callsite/CallSite;' }
>     stack: { 'org/codehaus/groovy/runtime/callsite/CallSite', 'java/lang/Class', uninitialized 10, uninitialized 10, '[Ljava/lang/Object;', '[Ljava/lang/Object;', integer, '[Ljava/lang/String;' }
>   Bytecode:
>     0000000: b800 144c 2b12 2132 1202 bb00 2359 04bd
>     0000010: 0004 5903 2ab4 001c 5305 bd00 2559 0312
>     0000020: 2753 5904 1229 53b7 002c b900 3203 0057
>     0000030: b1                                     
> 
> java.lang.VerifyError: Bad type on operand stack
> Exception Details:
>   Location:
>     q.main([Ljava/lang/String;)V @21: getfield
>   Reason:
>     Type '[Ljava/lang/String;' (current frame, stack[7]) is not assignable to 'q'
>   Current Frame:
>     bci: @21
>     flags: { }
>     locals: { '[Ljava/lang/String;', '[Lorg/codehaus/groovy/runtime/callsite/CallSite;' }
>     stack: { 'org/codehaus/groovy/runtime/callsite/CallSite', 'java/lang/Class', uninitialized 10, uninitialized 10, '[Ljava/lang/Object;', '[Ljava/lang/Object;', integer, '[Ljava/lang/String;' }
>   Bytecode:
>     0000000: b800 144c 2b12 2132 1202 bb00 2359 04bd
>     0000010: 0004 5903 2ab4 001c 5305 bd00 2559 0312
>     0000020: 2753 5904 1229 53b7 002c b900 3203 0057
>     0000030: b1                                     
> 
> 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> 129 ocs /tmp> 
> ===
> 
>> On 27 May 2020, at 23:42, ocs@ocs.cz <ma...@ocs.cz> wrote:
>> 
>> 484 ocs /tmp> <q.groovy 
>> class q {
>>  static main(av) {
>>    new Foo().test()
>>  }
>> }
>> class Foo extends Root { }
>> class Root {
>>    private _objects=[]
>>    void test() {
>>        println "this is OK"
>>        _objects<<'hi'
>>        println "this crashes"
>>        1.times { _objects<<it }
>>    }
>> }
>> 485 ocs /tmp> /usr/local/groovy-3.0.4/bin/groovy q
>> this is OK
>> this crashes
>> Caught: groovy.lang.MissingPropertyException: No such property: _objects for class: Foo
>> groovy.lang.MissingPropertyException: No such property: _objects for class: Foo
>> 	at Root$_test_closure1.doCall(q.groovy:13)
>> 	at Root.test(q.groovy:13)
>> 	at Root$test.call(Unknown Source)
>> 	at q.main(q.groovy:3)
>> 486 ocs /tmp> 
>> 
> 


Re: do I miss something here, or is this a Groovy bug?

Posted by Paul King <pa...@asert.com.au>.
We should never throw a VerifyError, so that is a bug. But you probably
don't want to use "this" in a static context. You probably just want
$q.metaClass or ${getMetaClass()}.

Cheers, Paul.


On Fri, Jun 5, 2020 at 9:33 PM OCsite <oc...@ocs.cz> wrote:

> And another thing which I don't understand and seems highly suspicious —
> do I just miss something of importance, or is it a bug?
>
> ===
> 127 ocs */tmp>* <q.groovy
> class q {
>   static main(av) {
>     println "my MC is $this.metaClass"
>   }
> }
> 128 ocs */tmp>* /usr/local/groovy-3.0.4/bin/groovy q
> Caught: java.lang.VerifyError: Bad type on operand stack
> Exception Details:
>   Location:
>     q.main([Ljava/lang/String;)V @21: getfield
>   Reason:
>     Type '[Ljava/lang/String;' (current frame, stack[7]) is not assignable
> to 'q'
>   Current Frame:
>     bci: @21
>     flags: { }
>     locals: { '[Ljava/lang/String;',
> '[Lorg/codehaus/groovy/runtime/callsite/CallSite;' }
>     stack: { 'org/codehaus/groovy/runtime/callsite/CallSite',
> 'java/lang/Class', uninitialized 10, uninitialized 10,
> '[Ljava/lang/Object;', '[Ljava/lang/Object;', integer,
> '[Ljava/lang/String;' }
>   Bytecode:
>     0000000: b800 144c 2b12 2132 1202 bb00 2359 04bd
>     0000010: 0004 5903 2ab4 001c 5305 bd00 2559 0312
>     0000020: 2753 5904 1229 53b7 002c b900 3203 0057
>     0000030: b1
>
> java.lang.VerifyError: Bad type on operand stack
> Exception Details:
>   Location:
>     q.main([Ljava/lang/String;)V @21: getfield
>   Reason:
>     Type '[Ljava/lang/String;' (current frame, stack[7]) is not assignable
> to 'q'
>   Current Frame:
>     bci: @21
>     flags: { }
>     locals: { '[Ljava/lang/String;',
> '[Lorg/codehaus/groovy/runtime/callsite/CallSite;' }
>     stack: { 'org/codehaus/groovy/runtime/callsite/CallSite',
> 'java/lang/Class', uninitialized 10, uninitialized 10,
> '[Ljava/lang/Object;', '[Ljava/lang/Object;', integer,
> '[Ljava/lang/String;' }
>   Bytecode:
>     0000000: b800 144c 2b12 2132 1202 bb00 2359 04bd
>     0000010: 0004 5903 2ab4 001c 5305 bd00 2559 0312
>     0000020: 2753 5904 1229 53b7 002c b900 3203 0057
>     0000030: b1
>
> at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method)
> at
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> 129 ocs */tmp>*
> ===
>
> On 27 May 2020, at 23:42, ocs@ocs.cz wrote:
>
> 484 ocs /tmp> <q.groovy
> class q {
>  static main(av) {
>    new Foo().test()
>  }
> }
> class Foo extends Root { }
> class Root {
>    private _objects=[]
>    void test() {
>        println "this is OK"
>        _objects<<'hi'
>        println "this crashes"
>        1.times { _objects<<it }
>    }
> }
> 485 ocs /tmp> /usr/local/groovy-3.0.4/bin/groovy q
> this is OK
> this crashes
> Caught: groovy.lang.MissingPropertyException: No such property: _objects
> for class: Foo
> groovy.lang.MissingPropertyException: No such property: _objects for
> class: Foo
> at Root$_test_closure1.doCall(q.groovy:13)
> at Root.test(q.groovy:13)
> at Root$test.call(Unknown Source)
> at q.main(q.groovy:3)
> 486 ocs /tmp>
>
>
>

Re: do I miss something here, or is this a Groovy bug?

Posted by Jochen Theodorou <bl...@gmx.org>.
On 05.06.20 13:33, OCsite wrote:
> And another thing which I don't understand and seems highly suspicious —
> do I just miss something of importance, or is it a bug?
>
> ===
> 127 ocs*/tmp>* <q.groovy
> class q {
>    static main(av) {
>      println "my MC is $this.metaClass"
>    }
> }
> 128 ocs*/tmp>* /usr/local/groovy-3.0.4/bin/groovy q
> Caught: java.lang.VerifyError: Bad type on operand stack

every VerifyError has to be considered as bug.

bye Jochen