Re: GString to String

Posted by Jacques Le Roux on
URL: http://ofbiz.116.s1.nabble.com/GString-to-String-tp4765301p4765599.html

There is none, because, as shown in the log below

    <<No special conversion required for org.codehaus.groovy.runtime.GStringImpl to String, returning object.toString(). >>

So it does the same thing, but prevents an useless error messages.

The change in ObjectType.java is simple:

-        if ("PlainString".equals(type)) {
+        if ("PlainString".equals(type)
+                || ("org.codehaus.groovy.runtime.GStringImpl".equals(obj.getClass().getName()) && "String".equals(type))) {
              return obj.toString();
          }

We can even suppress the Converters warning. It's a bit more complicated and I'm not sure it's needed (the case is quite obvious).

HTH

Jacques


Le 18/02/2021 à 17:51, Michael Brohl a écrit :

> What impact does this change have?
>
> Thanks,
>
> Michael
>
>
> Am 18.02.21 um 17:33 schrieb Jacques Le Roux:
>> Thanks Nicolas,
>>
>> Since nobody seems against I'll do so with https://issues.apache.org/jira/browse/OFBIZ-12182
>>
>> Jacques
>>
>> Le 15/02/2021 à 18:33, Nicolas Malin a écrit :
>>> I'm agree Jacques with that.
>>>
>>> Some time on specific customer code I was confronted to bad gstring
>>> conversion on groovy service because I forgot that "this ${code}" isn't
>>> a string in groovy !
>>>
>>> :)
>>>
>>> Nicolas
>>>
>>>
>>> On 13/02/2021 13:48, Jacques Le Roux wrote:
>>>> Hi,
>>>>
>>>> I spotted this error in log
>>>>
>>>> 2021-02-13 10:17:03,503 |jsse-nio-8443-exec-8
>>>> |Converters                    |W| *** No converter found, converting
>>>> from org.codehaus.groovy.runtime.GStringImpl to java.lang.String.
>>>> Please report this message to the developer community s
>>>> o a suitable converter can be created. ***
>>>> 2021-02-13 10:17:03,503 |jsse-nio-8443-exec-8
>>>> |ObjectType                    |E| null
>>>> java.lang.ClassNotFoundException: No converter found for
>>>> org.codehaus.groovy.runtime.GStringImpl->java.lang.String
>>>>          at
>>>> org.apache.ofbiz.base.conversion.Converters.getConverter(Converters.java:119)
>>>> ~[main/:?]
>>>>          at
>>>> org.apache.ofbiz.base.util.ObjectType.simpleTypeOrObjectConvert(ObjectType.java:328)
>>>> [main/:?]
>>>>          at
>>>> org.apache.ofbiz.base.util.ObjectType.simpleTypeOrObjectConvert(ObjectType.java:256)
>>>> [main/:?]
>>>>          at
>>>> org.apache.ofbiz.base.util.ObjectType.simpleTypeOrObjectConvert(ObjectType.java:375)
>>>> [main/:?]
>>>>          at
>>>> org.apache.ofbiz.entity.GenericEntity.set(GenericEntity.java:550)
>>>> [main/:?]
>>>>          at
>>>> org.apache.ofbiz.entity.GenericEntity.set(GenericEntity.java:502)
>>>> [main/:?]
>>>>          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>> ~[?:1.8.0_202]
>>>>          at
>>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>>>> ~[?:1.8.0_202]
>>>>          at
>>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>>>> ~[?:1.8.0_202]
>>>>          at java.lang.reflect.Method.invoke(Method.java:498)
>>>> ~[?:1.8.0_202]
>>>>          at
>>>> org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:101)
>>>> [groovy-2.5.11.jar:2.5.11]
>>>>          at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
>>>> [groovy-2.5.11.jar:2.5.11]
>>>>          at
>>>> groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2754)
>>>> [groovy-2.5.11.jar:2.5.11]
>>>>          at
>>>> groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3809)
>>>> [groovy-2.5.11.jar:2.5.11]
>>>>          at
>>>> org.codehaus.groovy.runtime.InvokerHelper.setProperty(InvokerHelper.java:217)
>>>> [groovy-2.5.11.jar:2.5.11]
>>>>          at
>>>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.setProperty(ScriptBytecodeAdapter.java:496)
>>>> [groovy-2.5.11.jar:2.5.11]
>>>>          at
>>>> DataServices.saveLocalFileDataResource(DataServices.groovy:280)
>>>> [script:?]
>>>>          at DataServices$saveLocalFileDataResource.callCurrent(Unknown
>>>> Source) [script:?]
>>>>          at
>>>> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51)
>>>> [groovy-2.5.11.jar:2.5.11]
>>>>          at
>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:156)
>>>> [groovy-2.5.11.jar:2.5.11]
>>>>          at
>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:168)
>>>> [groovy-2.5.11.jar:2.5.11]
>>>>          at
>>>> DataServices.attachUploadToDataResource(DataServices.groovy:191)
>>>> [script:?]
>>>> [...]
>>>> 2021-02-13 10:17:03,507 |jsse-nio-8443-exec-8
>>>> |ObjectType                    |I| No special conversion required for
>>>> org.codehaus.groovy.runtime.GStringImpl to String, returning
>>>> object.toString().
>>>>
>>>> To prevent this message, I propose to bypass GString to String
>>>> conversion.
>>>>
>>>> What do you think?
>>>>
>>>> Jacques
>>>>