oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.3k stars 1.63k forks source link

Cannot convert "1682293037722628098'(1anguage: Java, type: com.oracle.truffle.api.strings.Trufflestring) to Java type "java.lang .0bject[]':Unsupported target type #9438

Open dandelion2 opened 2 months ago

dandelion2 commented 2 months ago

While compiling a JavaScript script using GraalVM, we've encountered an intermittent issue when calling a Java interface with variable arguments defined as follows:

java public Object queryForMap(final String sql, Object ... args);

The corresponding JavaScript call to the method is structured like this:

javascript const selectSql = "select code, product_id as productId, ts_storage_id as tsStorageId from device where id = ?"; const deviceInfo = jdbcClient.queryForMap(selectSql, "1682293037722628098");

Initially, the script execution occasionally results in the error: "Cannot convert '1682293037722628098' to Java type 'java.lang.Object[]': Unsupported target type." Interestingly, after several attempts, the issue does not consistently manifest, making it difficult to reproduce.

selhagani commented 2 months ago

Hi @dandelion2,

Thank you for reaching out to us. Could you please share the version of GraalVM you're using, your OS, your system's architecture and a concise reproducer alongside the steps needed to reproduce the issue?

I understand that the execution of the script multiple times may end up leading to the issue not manifesting consistently but we still need it to test nevertheless.

Thank you

dandelion2 commented 2 months ago

The version of GraalVM I am using is graalvm-ce-java11-linux-amd64-22.3.1. The reproduction script, with business processing logic removed, is as follows: Java code: // Query the database public Map<String, Object> queryForMap(final String sql, Object ... args) { if (StringUtils.isBlank(sql)){ throw new DandelionException("mysql queryForMap error, SQL must not be null"); } // SQL validation checkSql(sql); try { return jdbcTemplate.queryForMap(sql, args); } catch (EmptyResultDataAccessException e){ return null; } catch (Exception e) { throw new DandelionException("mysql queryForMap error,"+e.getMessage(), e); } } // Register Java object context.eval("js", "var jdbcClient = Java.type('com.example.JsJdbc').create()"); JavaScript code: const selectSql = "SELECT code, product_id as productId, ts_storage_id as tsStorageId FROM device WHERE id = ?"; const deviceInfo = jdbcClient.queryForMap(selectSql, "1682293037722628098");

selhagani commented 1 month ago

Could you try testing with the latest available GraalVM version to see if the issue still presist? You can find it using this link: https://github.com/graalvm/graalvm-ce-builds/releases