'afterUpdate' method raises exception

Hi,

I’m trying to implement the ‘afterUpdate’ event handler. Here is my code (method signature generated by the console):
@Asset( “SignalsTest” )
public class SignalsTestTableEventHandler extends com.backendless.servercode.extension.PersistenceExtender
{
@Override
public void afterUpdate( RunnerContext context, SignalsTest signalstest, ExecutionResult result ) throws Exception
{
int i = 666;
}
}

When I make an update to an object in the table I get the following error:

BackendlessErrorDomain Code=0 “class java.util.HashMap cannot be cast to class com.helpapaw.models.SignalsTest (java.util.HashMap is in module java.base of loader ‘bootstrap’; com.helpapaw.models.SignalsTest is in unnamed module of loader java.net.URLClassLoader @62ddd21b)” UserInfo={NSLocalizedDescription=class java.util.HashMap cannot be cast to class com.helpapaw.models.SignalsTest (java.util.HashMap is in module java.base of loader ‘bootstrap’; com.helpapaw.models.SignalsTest is in unnamed module of loader java.net.URLClassLoader @62ddd21b)}

Looks like the method signature or the object passed to the method is of the wrong type.

Thanks for your help!

I have a few questions for you:

  1. Does the problem happen in both Debug and Production modes?
  2. Could you please check the version of code runner you use? (it prints it our when you run it in debug or deploy to prod).

Regards,
Mark

Hi Mark,

  1. It happens in Debug mode. Haven’t tried it in Production as I don’t want to deploy buggy code.
  2. Version: 6.0.10, Build id: 198337

Let me know if you need more info!

Best,
Milen

Hi @milen-marinov!

Could you, please, provide your App ID also?

Regards, Andriy

Sure, BDCD56B9-351A-E067-FFA4-9EA9CF2F4000

@milen-marinov

I was able to reproduce this problem in my own app. Internal ticket BKNDLSS-22671 was created for it. We will notify you when it will be fixed. As temporary bypass you can remove model classes mappins for this table and work directly with Map instances.
Sorry for inconvenience.

Regards, Andriy

1 Like

Hello @milen-marinov

We’ve just updated cloud servers with a fix for the issue you described above. Could you kindly let us know whether fix works for you well?

Regards,
Inna

Hello Inna,

Unfortunately, the fix is not working for me. I downloaded a new project from the console and added a single line in the afterUpdate method so I can put a breakpoint:
@Override
public void afterUpdate( RunnerContext context, SignalsTest signalstest, ExecutionResult result ) throws Exception
{
// add your code here
int i = 666;
}

After updating a row in the SignalsTest table I still get the following error:

InvocationTask[ appId:BDCD56B9-351A-E067-FFA4-9EA9CF2F4000 ]\n Exception: java.lang.ClassCastException: class java.util.HashMap cannot be cast to class com.helpapaw.models.SignalsTest (java.util.HashMap is in module java.base of loader ‘bootstrap’; com.helpapaw.models.SignalsTest is in unnamed module of loader java.net.URLClassLoader @5ee34b1b)\n\tat com.helpapaw.events.persistence_service.SignalsTestTableEventHandler.afterUpdate(SignalsTestTableEventHandler.java:26)\n\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.base/java.lang.reflect.Method.invoke(Method.java:564)\n\tat com.backendless.coderunner.runtime.task.EventInvocationTask.runImpl(EventInvocationTask.java:114)\n\tat com.backendless.coderunner.runtime.executor.ExtendedRunnable.run(ExtendedRunnable.java:38)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)\n\tat java.base/java.lang.Thread.run(Thread.java:832)\n

If I disable the afterUpdate event handler from the console the operation passes without error.

Best Regards,
Milen Marinov

Hi @milen-marinov!

Sorry for invonvenience. We will investigate your case. I will write you back when I will have more information about this error.

Regards, Andriy

1 Like

Hi @milen-marinov!

Sorry for delay with response. I checked your case and found that error present only when both, beforeUpdate and afterUpdate, handlers are present for update action. When there is only one of them is present then everything works as expected. It caused by bug in handlers arguments typecast logic.

I have created internal ticket for this problem BKNDLSS-23042. We write you back when fix will be released. As bypass you can again return to maps instead of classes.
Sorry for inconvenience.

Regards, Andriy

1 Like

Hello, @milen-marinov

We’ve updated cloud servers with a fix for the issue you described above. Could you kindly let us know whether fix works for you well?

Regards,
Marina

Hi @Marina.Kan,

I just checked and the problem is fixed!

Best,
Milen