adobe / bridgeService

The BridgeService is a library that allows your project to access java code to which you do not have implicite and normal access. Use cases are JS/Python/C++ accessing Java objects or java objects that are protected, and that you do not want to distribute as a library.
MIT License
6 stars 3 forks source link

java.lang.ClassCastException when a method accepts an array as a second argument #176

Closed baubakg closed 1 month ago

baubakg commented 1 month ago

Expected Behaviour

A method should be able to accept an array under all circumstances

Actual Behaviour

We get an errror:

 "java.lang.ClassCastException: class java.lang.String cannot be cast to class java.util.List (java.lang.String and java.util.List are in module java.base of loader 'bootstrap')",
    "bridgeServiceException": "com.adobe.campaign.tests.bridge.service.exceptions.IBSRunTimeException",

Reproduce Scenario (including but not limited to)

Sample Code that illustrates the problem

create method like :

    public int testArrays6(String mm, String[] b) {
        return 1+b.length;
    }

Logs taken while reproducing problem

    "stackTrace": [
        "com.adobe.campaign.tests.bridge.service.JavaCalls.call(JavaCalls.java:80)",
        "com.adobe.campaign.tests.bridge.service.JavaCalls.submitCalls(JavaCalls.java:109)",
        "com.adobe.campaign.tests.bridge.service.IntegroAPI.lambda$startServices$7(IntegroAPI.java:147)",
        "spark.RouteImpl$1.handle(RouteImpl.java:72)",
        "spark.http.matching.Routes.execute(Routes.java:61)",
        "spark.http.matching.MatcherFilter.doFilter(MatcherFilter.java:134)",
        "spark.embeddedserver.jetty.JettyHandler.doHandle(JettyHandler.java:50)",
        "org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1598)",
        "org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)",
        "org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)",
        "org.eclipse.jetty.server.Server.handle(Server.java:516)",
        "org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:487)",
        "org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:732)",
        "org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:479)",
        "org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:277)",
        "org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)",
        "org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105)",
        "org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104)",
        "org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:883)",
        "org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1034)",
        "java.base/java.lang.Thread.run(Thread.java:834)"
    ]
maheshyem commented 1 month ago

Same thing works fine for lists though.

public int testArrays6(String mm, List<String> b) {
        return 1+b.length;
    }
baubakg commented 1 month ago

Problem does not show up if call is done as a simple Java call using the JavaCalls Object:

@Test
    public void issue176_callingMethodAcceptingStringAndArray() {
        JavaCalls l_myJavaCall = new JavaCalls();

        CallContent l_cc1 = new CallContent();
        l_cc1.setClassName(SimpleStaticMethods.class.getTypeName());
        l_cc1.setMethodName("methodAcceptingStringAndArray");
        String[] l_array = new String[]{"value1", "value2"};
        l_cc1.setArgs(new Object[]{"ASD", l_array});

        l_myJavaCall.getCallContent().put("fetchResults", l_cc1);

        JavaCallResults jcr = l_myJavaCall.submitCalls();

        assertThat("we should have succeeded", jcr.getReturnValues().keySet(), Matchers.containsInAnyOrder("fetchResults"));
    }
baubakg commented 1 month ago

There are two problems: