Business Logic - BackendlessDataQuery Causes AccessControlException

When creating a custom event handler, instantiating a new instance of the class BackendlessDataQuery results in an AccessControlException being thrown.

@BackendlessEvent( "getUserLogin" )
public class GetUserLoginEventHandler extends com.backendless.servercode.extension.CustomEventHandler
{
    
   private static final Logger log = Logger.getLogger( GetUserLoginEventHandler.class );

  @Override
  public Map handleEvent( RunnerContext context, Map eventArgs )
  {
     Map<String,String> retObj = new HashMap<>();
     
     BackendlessDataQuery query = new BackendlessDataQuery("where clause");
     
     //...
         
     // add your code here
     return retObj;
  }

Hi Tim,

I suspect the error occurs because of the following line:

private static final Logger log = Logger.getLogger( GetUserLoginEventHandler.class );

Internally it creates a log buffer and allocates a thread which submits log messages back to Backendless. CodeRunner (currently) does not allow extra threads and you end up getting an exception. We’re making changes to allow an additional thread. Meanwhile, try the following workaround:

Add the following line before you get an instance of ILogger:

LogBuffer.getInstance().setLogReportingPolicy( 1, 0 );

What this effectively does is it immediately submits a log message to our servers (which is what you want to happen anyway on the server side).

Regards,
Mark

Thanks Mark, this fixed the issue.

You might want to update the Logging documentation here http://backendless.com/documentation/business-logic/java/bl_logging.htm

Following the documentation is what caused the error :confused:

The doc has been updated. Thanks for pointing this out.

Regards,
Mark