Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
baubakg opened this issue Sep 30, 2024 · 3 comments · Fixed by #177
Closed

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

baubakg opened this issue Sep 30, 2024 · 3 comments · Fixed by #177
Labels
bug Something isn't working
Milestone

Comments

@baubakg
Copy link
Member

baubakg commented Sep 30, 2024

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)"
	]

@baubakg baubakg added the bug Something isn't working label Sep 30, 2024
@baubakg baubakg added this to the 2.11.17 milestone Sep 30, 2024
@maheshyem
Copy link

Same thing works fine for lists though.

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

@baubakg
Copy link
Member Author

baubakg commented Sep 30, 2024

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
Copy link
Member Author

baubakg commented Sep 30, 2024

There are two problems:

  • Bad code in the CallContent.castArgs method (root cause)
  • The log message cannot be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants