cancel
Showing results for 
Search instead for 
Did you mean: 

Getting java.lang.ArrayIndexOutOfBoundsException error while executing JCoFunction

jignesh_raval_aa
Explorer
0 Kudos

Hi,

I am trying to execute a custom RFC function using the SAP JCo library. The issue is only with the specific function. Other RFC function calls are working fine.

On executing the JCo function it gives the error "java.lang.ArrayIndexOutOfBoundsException. Index 0 out of range" exception. I am not getting any other detailed errors in the stack trace. Enabled the SAP JCo traces, but no error found inside traces.

The function accepts the number of import parameters. But even if the RFC call gets executed with/without parameters, it is throwing the same error.

Below is the code snippet:

CustomDestinationDataProvider customProvider = CustomDestinationDataProvider.getInstance();
if (!Environment.isDestinationDataProviderRegistered(){
Environment.registerDestinationDataProvider(customProvider);
}

Properties connectProperties = new Properties();
// Setting up all required connection properties...
customProvider.setDestinationProperties("SAP_BAPI", connectProperties);

JCoDestination destination = JCoDestinationManager.getDestination("SAP_BAPI");
JCoRepository repository = destination.getRepository();

JCoContext.begin(destination);
JCoFunction function = repository.getFunction("Function_Name");
if (null == function)
{
return;
}
// Set function import, table and export parameters...

try {
function.execute(destination);
} catch (JCoException ex) {
// Handle JCoException
} catch (Exception ex) {
<strong>// Getting exception here : java.lang.ArrayIndexOutOfBoundsException. Index 0 out of range.</strong>
}
JCoContext.end(destination);

Accepted Solutions (0)

Answers (1)

Answers (1)

Ulrich_Schmidt
Product and Topic Expert
Product and Topic Expert

Without the complete stacktrace, it will not be possible to find the error reason here. If that Java program is a console program, can you add the line

ex.printStackTrace()

in the catch (Exception ex) block. Otherwise, you could save the stacktrace into a file like this:

catch (Exception ex)
try {
FileOutputStream out = new FileOutputStream("stack.txt");
ex.printStackTrace(new PrintStream(out));
out.close();
}
catch (IOException e) {}
}

Then let's take a look at the details.

jignesh_raval_aa
Explorer
0 Kudos

I will collect the stack trace from the console application. Meanwhile, I had enabled the SAP JCO trace logs and I don't see any error inside it. Below are the SAP JCO trace logs:

Runner-1562d533-9fe4-412d-a55e-5ea30e5c2442_517ef6cfee87d1e8 [16:00:16:506]: [JCoAPI] JCoClient.connect() success on handle [2/42742817]
Runner-1562d533-9fe4-412d-a55e-5ea30e5c2442_517ef6cfee87d1e8 [16:00:16:507]: [JCoAPI] Destination SAP_BAPI destinationID=SAP_BAPI|CONFIGURED_USER&100|USER1|EN|E6F6A3E17C77E26FF841A4DF1F463687|TRC executes ZOPS_ACMLDC_CHANGE sessionID=Client-40-1, threadID=0x28
Runner-1562d533-9fe4-412d-a55e-5ea30e5c2442_517ef6cfee87d1e8 [16:00:16:508]: [JCoAPI] Context.getConnection on destination SAP_BAPI (state: destination = STATEFUL, default = STATELESS)
Runner-1562d533-9fe4-412d-a55e-5ea30e5c2442_517ef6cfee87d1e8 [16:00:16:508]: [JCoAPI] PoolingFactory.getClient() on pool SAP_BAPI|CONFIGURED_USER&100|USER1|EN|E6F6A3E17C77E26FF841A4DF1F463687|TRC
Runner-1562d533-9fe4-412d-a55e-5ea30e5c2442_517ef6cfee87d1e8 [16:00:16:508]: [JCoAPI] PoolingFactory.getClient() returns handle [2/42742817]
	invoked at com.sap.conn.jco.rt.PoolingFactory.getClient(PoolingFactory.java:641)
	invoked at com.sap.conn.jco.rt.ConnectionManager.getClient(ConnectionManager.java:178)
	invoked at com.sap.conn.jco.rt.Context.getConnection(Context.java:143)
	invoked at com.sap.conn.jco.rt.RfcDestination.execute(RfcDestination.java:2023)
	invoked at com.sap.conn.jco.rt.RfcDestination.execute(RfcDestination.java:1988)
	invoked at com.sap.conn.jco.rt.AbapFunction.execute(AbapFunction.java:305)
	invoked at com.testapplication.executor.SAPFunctionImpl.run(SAPFunctionImpl.java:222)
	invoked at com.testapplication.commands.RunFunction.execute(RunFunction.java:96)
	invoked at com.testapplication.commands.RunFunctionCommand.execute(RunFunctionCommand.java:104)
	invoked at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	invoked at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	invoked at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	invoked at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	invoked at com.testapplication.bot.metrics.TimerInvocationHandler.invoke(TimerInvocationHandler.java:65)
	invoked at com.sun.proxy.$Proxy24.execute(Unknown Source)
	invoked at com.testapplication.bot.Bot_Untitled3.executeNode3(Bot_Untitled3.java:193)
	invoked at com.testapplication.bot.Bot_Untitled3.play(Bot_Untitled3.java:210)
	invoked at com.testapplication.Main.play(Main.java:63)
	invoked at com.testapplication.service.impl.BotLauncherImpl.runBot(BotLauncherImpl.java:22)
	invoked at com.testapplication.service.impl.DispatcherImpl.lambda$start$9(DispatcherImpl.java:573)
	invoked at com.testapplication.utils.ThreadUtil.lambda$withThreadContext$0(ThreadUtil.java:20)
	invoked at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(Unknown Source)
	invoked at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	invoked at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	invoked at java.base/java.lang.Thread.run(Unknown Source)

Runner-1562d533-9fe4-412d-a55e-5ea30e5c2442_517ef6cfee87d1e8 [16:00:16:509]: [JCoAPI] Context.getConnection on destination SAP_BAPI nothing found in the context - got client from ConnectionManager [2/42742817]
Runner-1562d533-9fe4-412d-a55e-5ea30e5c2442_517ef6cfee87d1e8 [16:00:16:509]: [JCoAPI] Context.releaseConnection on destination SAP_BAPI [2/42742817]
JCoPoolFinalizerThread [16:00:16:672]: [JCoAPI] Clearing all connection pools
JCoPoolFinalizerThread [16:00:16:673]: [JCoAPI] PoolingFactory.clear() on pool SAP_BAPI|CONFIGURED_USER&100|USER1|EN|E6F6A3E17C77E26FF841A4DF1F463687|TRC&REP
JCoPoolFinalizerThread [16:00:16:673]: [JCoAPI] JCoClient.disconnect() on handle [1/42729802]
JCoPoolFinalizerThread [16:00:16:673]: [JCoRFC] Disconnect before RfcClose(1)
JCoPoolFinalizerThread [16:00:16:707]: [JCoRFC] Disconnect after RfcClose(1)
JCoPoolFinalizerThread [16:00:16:708]: [JCoRFC] Release RFC handle [1/42729802] in thread 46: JCoPoolFinalizerThread (46: JCoPoolFinalizerThread)
JCoPoolFinalizerThread [16:00:16:708]: [JCoAPI] PoolingFactory.clear() on pool SAP_BAPI|CONFIGURED_USER&100|USER1|EN|E6F6A3E17C77E26FF841A4DF1F463687|TRC
JCoPoolFinalizerThread [16:00:16:708]: [JCoAPI] Closing all detached clients
jignesh_raval_aa
Explorer
0 Kudos

This is the stack trace that I am getting on the execute function.:

java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
	at com.sap.conn.jco.rt.AbstractRecord.decodeSTRUCTURE(AbstractRecord.java:7148) ~[sapjco3.jar:20220521 0154 [3.1.6 (2022-05-18)]]
	at com.sap.conn.jco.rt.AbstractRecord.isInitialized(AbstractRecord.java:5362) ~[sapjco3.jar:20220521 0154 [3.1.6 (2022-05-18)]]
	at com.sap.conn.jco.rt.DefaultTable.isInitialized(DefaultTable.java:314) ~[sapjco3.jar:20220521 0154 [3.1.6 (2022-05-18)]]
	at com.sap.conn.jco.rt.AbstractRecord.isInitialized(AbstractRecord.java:5384) ~[sapjco3.jar:20220521 0154 [3.1.6 (2022-05-18)]]
	at com.sap.conn.jco.rt.ClientConnection.execute(ClientConnection.java:2163) ~[sapjco3.jar:20220521 0154 [3.1.6 (2022-05-18)]]
	at com.sap.conn.jco.rt.ClientConnection.execute(ClientConnection.java:2079) ~[sapjco3.jar:20220521 0154 [3.1.6 (2022-05-18)]]
	at com.sap.conn.jco.rt.RfcDestination.execute(RfcDestination.java:2235) ~[sapjco3.jar:20220521 0154 [3.1.6 (2022-05-18)]]
	at com.sap.conn.jco.rt.RfcDestination.execute(RfcDestination.java:2199) ~[sapjco3.jar:20220521 0154 [3.1.6 (2022-05-18)]]
	at com.sap.conn.jco.rt.AbapFunction.execute(AbapFunction.java:305) ~[sapjco3.jar:20220521 0154 [3.1.6 (2022-05-18)]]
	at com.testapplication.executor.SAPFunctionImpl.run(SAPFunctionImpl.java:239) ~[bot-command-sapbapi-2.9.0-debug-1.6.jar:?]
	at com.testapplication.commands.RunFunction.execute(RunFunction.java:96) ~[bot-command-sapbapi-2.9.0-debug-1.6.jar:?]
	at com.testapplication.commands.RunFunctionCommand.execute(RunFunctionCommand.java:104) ~[bot-command-sapbapi-2.9.0-debug-1.6.jar:?]
	at jdk.internal.reflect.GeneratedMethodAccessor179.invoke(Unknown Source) ~[?:?]
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:?]
	at com.testapplication.bot.metrics.TimerInvocationHandler.invoke(TimerInvocationHandler.java:65) ~[bot-launcher.jar:?]
	at com.sun.proxy.$Proxy27.execute(Unknown Source) ~[?:?]
	at com.testapplication.bot.Bot_SpainUnload_copy_1_.executeNode204(Bot_SpainUnload_copy_1_.java:3386) ~[?:?]
	at com.testapplication.bot.Bot_SpainUnload_copy_1_.play(Bot_SpainUnload_copy_1_.java:3911) ~[?:?]
	at com.testapplication.Main.play(Main.java:63) ~[?:?]
	at com.testapplication.service.impl.BotLauncherImpl.runBot(BotLauncherImpl.java:22) ~[bot-launcher.jar:?]
	at com.testapplication.service.impl.DispatcherImpl.lambda$start$9(DispatcherImpl.java:573) ~[bot-launcher.jar:?]
	at com.testapplication.utils.ThreadUtil.lambda$withThreadContext$0(ThreadUtil.java:20) ~[bot-launcher.jar:?]
	at java.util.concurrent.CompletableFuture$AsyncSupply.run(Unknown Source) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:?]
	at java.lang.Thread.run(Unknown Source) [?:?]
Ulrich_Schmidt
Product and Topic Expert
Product and Topic Expert
0 Kudos

This looks like there is some "inconsistency" in the function module's metadata in the backend's DDIC, which throws JCo off track!

To test this theory, can you please check in SE37, whether ZOPS_ACMLDC_CHANGE or any of the structures, tables or data elements it uses, has some kind of DDIC activation error. Or uses some "very complicated" nested structures.

If ABAP itself has no problem with that FM, it could be a bug in DDIF_FIELDINFO_GET or in RFC_METADATA_GET. (There have been bugs in these FMs in the past, which for certain border cases lead to inconsistent metadata (lengths, offsets and alignments of fields and child-fields) returned from the DDIC lookup, which then trips off JCo. So you might want to search the ABAP notes of your current SAP release for the names of these two FMs.

jignesh_raval_aa
Explorer
0 Kudos

@Ulrich Schmidt Thanks for your detailed input. I will check the function structure in SE37.

I wanted to add that when trying to execute this BAPI from a .NET application using the .NET SAP connector NCo (sapnco.dll), it is working fine without any error. The issue is only observed in the Java application with JCo. Even when we try to call the function with parameters (Import, Export, Table) Or without parameters, still it gives the same error.

Ulrich_Schmidt
Product and Topic Expert
Product and Topic Expert
0 Kudos

In that case it is definitely worth to try the latest JCo patch level 3.1.8. (I see you are still on 3.1.6.) Perhaps it is indeed a "special case", which JCo treats incorrectly, but latest NCo and JCo version can handle?!

If there is still the same error with JCo 3.1.8, chances are high that it needs to be debugged and fixed by JCo support. In that case, is it possible for you to somehow export ZOPS_ACMLDC_CHANGE from ABAP/SE37 and open a SAP support ticket with it? (I think, the actual ABAP coding inside the FM is irrelevant, important is only the precise definition of exporting/importing/tables parameters.)

jignesh_raval_aa
Explorer
0 Kudos

@Ulrich Schmidt I tried the JCo 3.1.8 version, but no luck. One thing that I observed is, I did print the JCo function XML using JcoFunciton.toXML() API and checked the function parameters.

I found the below-suspected parameters, which might be causing the issue while reading function metadata:

<_-ACCGO_-GMO_RELEVANCY/>
<_-ACCGO_-ROYALTIES_ID/>
<_-ACCGO_-VENDOR/>
<_-ACCGO_-TECHNOLOGY/>
<_-ACCGO_-PERCENTAGE>0.00</_-ACCGO_-PERCENTAGE>

When I checked these parameters in SAP GUI, it was named /ACCGO/GMO_RELEVANCY (/ instead of _-).

So, Do you think this could be the issue? Is this the correct way to name the parameter Or Is there any other way to pass the parameter name as it is?

Thanks.

HAL9000
Product and Topic Expert
Product and Topic Expert

</ACCGO/GMO_RELEVANCY/> would not be valid XML, hence some characters are escaped. This is not an error.
Please create a SAP support case for the ArrayIndexOutofBoundsException situation on component BC-MID-CON-JCO with attaching full JCo 3.1.8 trace level 8 traces and the exception stack you are getting. This might be an unknown JCo bug which needs to be fixed.
Thanks and best regards,
Stefan