Code runner failing with exception

Hello,

Custom code on an API hook started failing with the following exception:

BackendlessFault{ code: ‘0’, message: ‘InvocationTask[ appId:BDCD56B9-351A-E067-FFA4-9EA9CF2F4000 ]\n Exception: java.lang.NullPointerException: Cannot invoke “java.lang.reflect.Method.invoke(Object, Object)” because “this.addHeader” is null\n\tat com.backendless.coderunner.runtime.task.EventInvocationTask.runImpl(EventInvocationTask.java:108)\n\tat com.backendless.coderunner.runtime.executor.ExtendedRunnable.run(ExtendedRunnable.java:42)\n\tat java.base/java.lang.Thread.run(Thread.java:833)\n’, detail: ‘InvocationTask[ appId:BDCD56B9-351A-E067-FFA4-9EA9CF2F4000 ]\n Exception: java.lang.NullPointerException: Cannot invoke “java.lang.reflect.Method.invoke(Object, Object)” because “this.addHeader” is null\n\tat com.backendless.coderunner.runtime.task.EventInvocationTask.runImpl(EventInvocationTask.java:108)\n\tat com.backendless.coderunner.runtime.executor.ExtendedRunnable.run(ExtendedRunnable.java:42)\n\tat java.base/java.lang.Thread.run(Thread.java:833)\n’, extendedData: ‘{}’ }

The code hasn’t been updated in a long time and was working fine until today (or a few days ago). This is affecting an app in production!

Hello @milen-marinov

for the last few days, there was no changes from our side. How can we reproduce the issue?

It’s triggered by this code from the client app:

        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put("objectId", "A8C13D23-2B42-41A2-8334-BEA890371008");
        dataMap.put("status", 1);

        Backendless.Data.of("SignalsTest").save(dataMap, new AsyncCallback<Map>() {
            @Override
            public void handleResponse(Map saveResponse) {
               ...
            }

            @Override
            public void handleFault(BackendlessFault fault) {
                ...
            }
        });

And you have the AppId in the first comment.

@milen-marinov

Thanks. I can reproduce it from the client side. But when I do the same on my Application I can not reproduce it. Could you please attach your business logic project that we can use to reproduce the issue? If there is some sensitive data you can send us it as message to the staff like described in the topic If you are a customer with Managed or Pro installation and send the link to the message in this topic

No sensitive data, this is the hook that is triggered by the aforementioned example:

@Asset( "SignalsTest" )
public class SignalsTestTableEventHandler extends com.backendless.servercode.extension.PersistenceExtender<SignalsTest>
{
  @Override
  public void beforeUpdate( RunnerContext context, SignalsTest signalstest ) throws Exception
  {
    if (signalstest.getStatus() != null) {
      Map oldSignal = Backendless.Data.of("SignalsTest").findById(signalstest.getObjectId());
      Integer oldStatus = (Integer) oldSignal.get("status");
      if (!oldStatus.equals(signalstest.getStatus())) {
        HashMap comment = new HashMap();
        comment.put( "text", "{\"old\":" + oldStatus + ",\"new\":" + signalstest.getStatus() + "}");
        comment.put( "signalID", signalstest.getObjectId() );
        comment.put( "type", "status_change" );
        Map response = Backendless.Data.of( "FINComment" ).save( comment );
        List users = new ArrayList();
        BackendlessUser user = Backendless.UserService.findById(context.getUserId());
        users.add(user);
        Backendless.Data.of("FINComment").setRelation(response, "author", users);
      }
    }
  }
}

Again - this is something that was tested and worked fine for a long time. It started failing only recently but I cannot tell when exactly.

@milen-marinov
I have created the new model in your application signal_test_model and created a project which can be found in the following private message https://support.backendless.com/t/project-for-code-runner-failing-with-exception/16831

Then I have turned off your event handler:

And looks like it works, but to be sure I need to have a valid user, because I got the following error:

{
	"code": 0,
	"message": "InvocationTask[ appId:BDCD56B9-351A-E067-FFA4-9EA9CF2F4000 ]
 Exception: java.lang.IllegalArgumentException: Identity cannot be null
\\tat com.backendless.UserService.findById(UserService.java:577)
\\tat com.helpapaw.events.persistence_service.SignalsTestTableEventHandler.beforeUpdate(SignalsTestTableEventHandler.java:38)
\\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
\\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
\\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
\\tat java.base/java.lang.reflect.Method.invoke(Method.java:568)
\\tat com.backendless.coderunner.runtime.task.EventInvocationTask.runImpl(EventInvocationTask.java:111)
\\tat com.backendless.coderunner.runtime.executor.ExtendedRunnable.run(ExtendedRunnable.java:42)
\\tat java.base/java.lang.Thread.run(Thread.java:833)
"
}

I guess it is because I have not logged in.

So to fix your issue make sure your project uses the same dependencies as my project. Or just move you code to this project.

@sergey.kuk I don’t understand - why should the previously working project be migrated? Did you introduce breaking changes?

@milen-marinov

There were some changes about a month ago that may break the backward compatibility, for existing applications. So it may cause the issue you have. And unfortunately, we are not able to revert the changes. So the only way you can fix it is to migrate to a new project. We are really sorry for the inconvenience.

So:

  1. You introduced breaking changes without a warning and transition period
  2. You didn’t communicate this to uses even post-factum

This is unacceptable! Not that I’m surprised given it’s far from the first time something like this happens…
And on top of that prices are increasing X-fold! Migration is imminent, indeed!

When I tried to debug the code from the project you sent me it also fails with the following exception:

Jun 13, 2023 2:41:38 PM com.backendless.coderunner.runtime.task.EventInvocationTask
SEVERE: Can’t prepare HeadersManager class.
java.lang.ClassNotFoundException: com.backendless.HeadersManager$HeadersEnum
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:587)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
at com.backendless.coderunner.runtime.task.EventInvocationTask.(EventInvocationTask.java:53)
at com.backendless.coderunner.runtime.CodeExecutor.invokeEvent(CodeExecutor.java:67)
at com.backendless.coderunner.processor.MessageDispatcher.onMessageReceived(MessageDispatcher.java:46)
at com.backendless.coderunner.processor.AbstractMessageProcessor.run(AbstractMessageProcessor.java:90)

[WEBORB ERROR, Thread-41, 06:13:23 02:41:38] unable to find matching server-side type for SignalsTest

hello @milen-marinov

The issue with SEVERE: Can’t prepare HeadersManager class. goes from another part of SDK, it should not impact your code. We are working on the issue with the header manager.

Well, I don’t know what should and should not impact my code but in the client app I still get the following fault when the project you sent me is deployed and enabled:

BackendlessFault{ code: ‘0’, message: ‘InvocationTask[ appId:BDCD56B9-351A-E067-FFA4-9EA9CF2F4000 ]\n Exception: java.lang.NullPointerException: Cannot invoke “java.lang.reflect.Method.invoke(Object, Object)” because “this.addHeader” is null\n\tat com.backendless.coderunner.runtime.task.EventInvocationTask.runImpl(EventInvocationTask.java:108)\n\tat com.backendless.coderunner.runtime.executor.ExtendedRunnable.run(ExtendedRunnable.java:42)\n\tat java.base/java.lang.Thread.run(Thread.java:833)\n’, detail: ‘InvocationTask[ appId:BDCD56B9-351A-E067-FFA4-9EA9CF2F4000 ]\n Exception: java.lang.NullPointerException: Cannot invoke “java.lang.reflect.Method.invoke(Object, Object)” because “this.addHeader” is null\n\tat com.backendless.coderunner.runtime.task.EventInvocationTask.runImpl(EventInvocationTask.java:108)\n\tat com.backendless.coderunner.runtime.executor.ExtendedRunnable.run(ExtendedRunnable.java:42)\n\tat java.base/java.lang.Thread.run(Thread.java:833)\n’, extendedData: ‘{}’ }

When I disable the event handler, call succeeds without executing the handler logic (as expected).

When I run the following code

I can not reproduce the issue you have shown, I got the following:

BackendlessFault{ code: '1012', message: 'User has no permission to update entity 'SignalsTest'.', detail: 'User has no permission to update entity 'SignalsTest'.', extendedData: '{}' }

I have deployed the project I have sent you, could you please try to execute client with current deployed code, does it works?

No, it doesn’t! It fails with the aforementioned exception. In your case it just fails earlier for a different reason - because you are running it as an anonymous user. I guess if you are modifying my production app’s cloud code, you can also create a temporary use and try with it. BTW, I would also expect that you have logs of such exceptions in your code…

@milen-marinov ok now I was able to reproduce the issue, and on an isolated environment. I have increased the priority for the task to BLOCKER. Ingeneer is already working on it, we will let you know any news as soon as it is possible.

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