Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Texo] ClassCastException String cast to JSONObject
[Texo] ClassCastException String cast to JSONObject [message #1065375] Tue, 25 June 2013 13:32 Go to next message
Bastian Wagenfeld is currently offline Bastian Wagenfeld
Messages: 162
Registered: January 2013
Senior Member
Hi Martin,

I've got a ClassCastException which came from nowhere... I don't really understand why this happens, since I don't know what I changed compared to the last running version. I'm using the Texo version with qualifier 201304010838.

So this is the stack trace:
java.lang.ClassCastException: java.lang.String cannot be cast to org.json.JSONObject
	at org.eclipse.emf.texo.json.BaseJSONModelConverter.convertSingleEReference(BaseJSONModelConverter.java:261)
	at org.eclipse.emf.texo.json.BaseJSONModelConverter.convertContent(BaseJSONModelConverter.java:228)
	at org.eclipse.emf.texo.json.BaseJSONModelConverter.doConvert(BaseJSONModelConverter.java:113)
	at org.eclipse.emf.texo.json.BaseJSONModelConverter.convertManyEReference(BaseJSONModelConverter.java:376)
	at org.eclipse.emf.texo.json.BaseJSONModelConverter.convertContent(BaseJSONModelConverter.java:220)
	at org.eclipse.emf.texo.json.BaseJSONModelConverter.doConvert(BaseJSONModelConverter.java:113)
	at org.eclipse.emf.texo.json.BaseJSONModelConverter.convert(BaseJSONModelConverter.java:105)
	at org.eclipse.emf.texo.server.service.json.JSONServiceContext.getRequestData(JSONServiceContext.java:94)
	at org.eclipse.emf.texo.server.service.UpdateInsertModelOperation.internalExecute(UpdateInsertModelOperation.java:45)
	at org.eclipse.emf.texo.server.service.ModelOperation.execute(ModelOperation.java:59)
	at org.eclipse.emf.texo.server.web.WebServiceHandler.doPost(WebServiceHandler.java:111)
	at org.eclipse.emf.texo.server.web.WebServiceServlet.doPost(WebServiceServlet.java:65)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at de.test.cmp.filter.DatabaseSwitchFilter.doFilter(DatabaseSwitchFilter.java:42)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
	at java.lang.Thread.run(Thread.java:722)


The interessting thing is that the String that is to be cast is "null". It isn't null, but it has the value "null".
I would be glad, if you had a hint, how this could happen.

Best regards
Bastian
Re: [Texo] ClassCastException String cast to JSONObject [message #1065385 is a reply to message #1065375] Tue, 25 June 2013 14:03 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5335
Registered: July 2009
Senior Member
Hi Bastian,
Can you check/debug the upstream/source of the json. Where is the json created? In a the jsonresource or the json
eobject store? How does it arrive on the server.

That would give more clues.

gr. Martin

On 06/25/2013 03:32 PM, Bastian Wagenfeld wrote:
> Hi Martin,
>
> I've got a ClassCastException which came from nowhere... I don't really understand why this happens, since I don't know
> what I changed compared to the last running version. I'm using the Texo version with qualifier 201304010838.
>
> So this is the stack trace:
> java.lang.ClassCastException: java.lang.String cannot be cast to org.json.JSONObject
> at org.eclipse.emf.texo.json.BaseJSONModelConverter.convertSingleEReference(BaseJSONModelConverter.java:261)
> at org.eclipse.emf.texo.json.BaseJSONModelConverter.convertContent(BaseJSONModelConverter.java:228)
> at org.eclipse.emf.texo.json.BaseJSONModelConverter.doConvert(BaseJSONModelConverter.java:113)
> at org.eclipse.emf.texo.json.BaseJSONModelConverter.convertManyEReference(BaseJSONModelConverter.java:376)
> at org.eclipse.emf.texo.json.BaseJSONModelConverter.convertContent(BaseJSONModelConverter.java:220)
> at org.eclipse.emf.texo.json.BaseJSONModelConverter.doConvert(BaseJSONModelConverter.java:113)
> at org.eclipse.emf.texo.json.BaseJSONModelConverter.convert(BaseJSONModelConverter.java:105)
> at org.eclipse.emf.texo.server.service.json.JSONServiceContext.getRequestData(JSONServiceContext.java:94)
> at org.eclipse.emf.texo.server.service.UpdateInsertModelOperation.internalExecute(UpdateInsertModelOperation.java:45)
> at org.eclipse.emf.texo.server.service.ModelOperation.execute(ModelOperation.java:59)
> at org.eclipse.emf.texo.server.web.WebServiceHandler.doPost(WebServiceHandler.java:111)
> at org.eclipse.emf.texo.server.web.WebServiceServlet.doPost(WebServiceServlet.java:65)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
> at de.test.cmp.filter.DatabaseSwitchFilter.doFilter(DatabaseSwitchFilter.java:42)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
> at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
> at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
> at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
> at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
> at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
> at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
> at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
> at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
> at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
> at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
> at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
> at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
> at java.lang.Thread.run(Thread.java:722)
> The interessting thing is that the String that is to be cast is "null". It isn't null, but it has the value "null". I
> would be glad, if you had a hint, how this could happen.
>
> Best regards
> Bastian


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Texo] ClassCastException String cast to JSONObject [message #1065495 is a reply to message #1065385] Wed, 26 June 2013 07:09 Go to previous messageGo to next message
Bastian Wagenfeld is currently offline Bastian Wagenfeld
Messages: 162
Registered: January 2013
Senior Member
Hi,

So I debugged a lot and I now know this situation happens, if there is a single reference from one object to another which should be set null.

As an example:
{"update":[{"id":"{SN must be set}","_eclass":"plane|Instance","db_version":1,"db_Id":1649,"_id":"1649","description":"Description","part":{"_eclass":"plane|Part","db_Id":26,"_id":"26","_proxy":true,"_uri":"http://localhost:8080/test2/jsonws/plane|Part/26#","_title":""},"manufacturer":{"_eclass":"plane|Customer","db_Id":217,"_id":"217","_proxy":true,"_uri":"http://localhost:8080/test2/jsonws/plane|Customer/217#","_title":"Custom"},"children":[],"_uri":"http://localhost:8080/test2/jsonws/plane|Instance/1649#","aVersion":"null","_title":"{SN must be set}"}],"_eclass":"request|ActionType","delete":[],"insert":[],"_title":"{SN must be set}"}

Where the reference aVersion is null. aVersion should be an EObject, but is treated as a String.

Just this moment I got a similar error. There seems to be a null value which is mapped as "null" (String) and therefore cannot be transformed.
java.lang.NumberFormatException: For input string: "null"
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.lang.Long.parseLong(Long.java:441)
	at java.lang.Long.valueOf(Long.java:540)
	at org.eclipse.emf.ecore.impl.EcoreFactoryImpl.createELongObjectFromString(EcoreFactoryImpl.java:953)
	at org.eclipse.emf.ecore.impl.EcoreFactoryImpl.createFromString(EcoreFactoryImpl.java:158)
	at org.eclipse.emf.texo.provider.IdProvider.convertIdStringToId(IdProvider.java:150)
	at org.eclipse.emf.texo.server.service.RetrieveModelOperation.internalExecute(RetrieveModelOperation.java:162)
	at org.eclipse.emf.texo.server.service.ModelOperation.execute(ModelOperation.java:59)
	at org.eclipse.emf.texo.server.web.WebServiceHandler.doGet(WebServiceHandler.java:89)
	at org.eclipse.emf.texo.server.web.WebServiceServlet.doGet(WebServiceServlet.java:57)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at de.kisters.praesto.filter.DatabaseSwitchFilter.doFilter(DatabaseSwitchFilter.java:42)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
	at java.lang.Thread.run(Thread.java:722)


The json strings are created in the JSONEObjectStore. I'm pretty confused, because these errors came from nowhere...

I really hope to find the reason for that.
Best regards
Bastian
Re: [Texo] ClassCastException String cast to JSONObject [message #1065906 is a reply to message #1065495] Fri, 28 June 2013 08:31 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5335
Registered: July 2009
Senior Member
Hi Bastian,
Sorry to ask, but can you debug the serialization code, to see why/where it happens?
The single ereferences are converted in the BaseModelJSONConverter.convertSingleEReference method. There is an if
statement to handle null:
final T value = (T) eGet(source, eReference);
if (value == null) {
target.put(jsonPropName, JSONObject.NULL);
....

gr. Martin

On 06/26/2013 09:09 AM, Bastian Wagenfeld wrote:
> Hi,
>
> So I debugged a lot and I now know this situation happens, if there is a single reference from one object to another
> which should be set null.
>
> As an example: {"update":[{"id":"{SN must be
> set}","_eclass":"plane|Instance","db_version":1,"db_Id":1649,"_id":"1649","description":"Description","part":{"_eclass":"plane|Part","db_Id":26,"_id":"26","_proxy":true,"_uri":"http://localhost:8080/test2/jsonws/plane|Part/26#","_title":""},"manufacturer":{"_eclass":"plane|Customer","db_Id":217,"_id":"217","_proxy":true,"_uri":"http://localhost:8080/test2/jsonws/plane|Customer/217#","_title":"Custom"},"children":[],"_uri":"http://localhost:8080/test2/jsonws/plane|Instance/1649#","aVersion":"null","_title":"{SN
> must be set}"}],"_eclass":"request|ActionType","delete":[],"insert":[],"_title":"{SN must be set}"}
>
> Where the reference aVersion is null. aVersion should be an EObject, but is treated as a String.
>
> Just this moment I got a similar error. There seems to be a null value which is mapped as "null" (String) and therefore
> cannot be transformed.
> java.lang.NumberFormatException: For input string: "null"
> at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
> at java.lang.Long.parseLong(Long.java:441)
> at java.lang.Long.valueOf(Long.java:540)
> at org.eclipse.emf.ecore.impl.EcoreFactoryImpl.createELongObjectFromString(EcoreFactoryImpl.java:953)
> at org.eclipse.emf.ecore.impl.EcoreFactoryImpl.createFromString(EcoreFactoryImpl.java:158)
> at org.eclipse.emf.texo.provider.IdProvider.convertIdStringToId(IdProvider.java:150)
> at org.eclipse.emf.texo.server.service.RetrieveModelOperation.internalExecute(RetrieveModelOperation.java:162)
> at org.eclipse.emf.texo.server.service.ModelOperation.execute(ModelOperation.java:59)
> at org.eclipse.emf.texo.server.web.WebServiceHandler.doGet(WebServiceHandler.java:89)
> at org.eclipse.emf.texo.server.web.WebServiceServlet.doGet(WebServiceServlet.java:57)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
> at de.kisters.praesto.filter.DatabaseSwitchFilter.doFilter(DatabaseSwitchFilter.java:42)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
> at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
> at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
> at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
> at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
> at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
> at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
> at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
> at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
> at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
> at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
> at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
> at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
> at java.lang.Thread.run(Thread.java:722)
>
> The json strings are created in the JSONEObjectStore. I'm pretty confused, because these errors came from nowhere...
>
> I really hope to find the reason for that.
> Best regards
> Bastian
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Texo] ClassCastException String cast to JSONObject [message #1065955 is a reply to message #1065906] Fri, 28 June 2013 13:22 Go to previous message
Bastian Wagenfeld is currently offline Bastian Wagenfeld
Messages: 162
Registered: January 2013
Senior Member
Hi,

that's right, it sets JSONObject.NULL, but in BaseJSONModelConverter.convertSingleEReference the value is from type String. Maybe somewhere JSONObject.NULL.toString() is used. I fixed it (for now) with just checking, if it's a String or equals "null". That isn't very clean, but it's ok for my use cases...
Maybe my data model was just corrupted. I'll try to do some researches on it after the weekend.

It's just odd that this happened suddenly. I didn't experience it before, altough I persisted null about a million times Smile
I thought it could have been something like a classloader issue. Were two different JSONObject.NULL "classes" were loaded. But this is just a shot in the dark.

I'll have a closer look at this.
Thanks for your help so far Smile

Best regards
Bastian
Previous Topic:[Texo] Using BLOBs
Next Topic:Is there a headless feature for running MWE2 workflows?
Goto Forum:
  


Current Time: Thu Oct 02 00:32:17 GMT 2014

Powered by FUDForum. Page generated in 0.01923 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software