{"id":25423823,"url":"https://github.com/jeffque/graalvm-regression","last_synced_at":"2025-05-14T00:32:50.710Z","repository":{"id":277544961,"uuid":"925237478","full_name":"jeffque/graalvm-regression","owner":"jeffque","description":"https://github.com/oracle/graaljs/issues/886","archived":false,"fork":false,"pushed_at":"2025-02-14T13:51:50.000Z","size":15,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-14T14:35:21.242Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jeffque.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-31T13:53:47.000Z","updated_at":"2025-02-14T13:51:53.000Z","dependencies_parsed_at":"2025-02-14T14:46:41.508Z","dependency_job_id":null,"html_url":"https://github.com/jeffque/graalvm-regression","commit_stats":null,"previous_names":["jeffque/graalvm-regression"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffque%2Fgraalvm-regression","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffque%2Fgraalvm-regression/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffque%2Fgraalvm-regression/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffque%2Fgraalvm-regression/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jeffque","download_url":"https://codeload.github.com/jeffque/graalvm-regression/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254046265,"owners_count":22005566,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-16T22:46:42.233Z","updated_at":"2025-05-14T00:32:50.676Z","avatar_url":"https://github.com/jeffque.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"Reproducing issue https://github.com/oracle/graaljs/issues/886 as a standalone maven project.\n\n## How to reproduce\n\n\u003e this must be run at the branch [`reproduce-split-misbehavior`](https://github.com/jeffque/graalvm-regression/tree/reproduce-split-misbehavior)\n\u003e \n\u003e Be sure to `git switch reproduce-split-misbehavior` before runing this code\n\nTo run with graalvm-24, version that the bug was reported:\n\n```bash\n# be sure the branch is `reproduce-split-misbehavior`\n./mvnw compile exec:java -P graalvm-24\n```\n\nIt will yield the error:\n\n```none\nException in thread \"main\" TypeError: k.equals is not a function\n\tat \u003cjs\u003e :=\u003e(Unnamed:6:154-169)\n\tat com.oracle.truffle.polyglot.PolyglotFunctionProxyHandler.invoke(PolyglotFunctionProxyHandler.java:151)\n```\n\nTo run the previous known version with no error (graalvm-20):\n\n```bash\n# be sure the branch is `reproduce-split-misbehavior`\n./mvnw compile exec:java -P graalvm-20\n```\n\nIt will print:\n\n```none\nOptional[true]\n```\n\n\n## Proposed fix\n\nThe issue has been answered https://github.com/oracle/graaljs/issues/886#issuecomment-2630920074. By the answer, I concluded that it was not something configurable at runtime, that there must a change in code whatsoever.\n\nSo, to address this, I propose to add a code in the middle to ensure creating a more JS-ish code. This will ensure that the produced array is indeed js-array compatible.\n\n```js\nfunction as_js_array(arr) {\n\t// check if it is a java obj by probing the `equals` method existence\n\tif (!arr.equals) {\n\t\t// does not exist, return it\n\t\tconsole.debug(\"not java\")\n\t\treturn arr;\n\t}\n\tconsole.debug(\"yep, this is java, transforming to js array\")\n\t// ok, it is java after all\n\t// assuming it was a java array, this can be checked further to be sure\n\treturn java.util.stream.Stream.of(arr)\n\t\t.reduce([], (acc, el) =\u003e [...acc, el]);\n}\n```\n\nWith this function, let's run this sample?\n\n```js\nfunction as_js_array(arr) {\n\t// check if it is a java obj by probing the `equals` method existence\n\tif (!arr.equals) {\n\t\t// does not exist, return it\n\t\tconsole.debug(\"not java\")\n\t\treturn arr;\n\t}\n\tconsole.debug(\"yep, this is java, transforming to js array\")\n\t// ok, it is java after all\n\t// assuming it was a java array, this can be checked further to be sure\n\treturn java.util.stream.Stream.of(arr)\n\t\t.reduce([], (acc, el) =\u003e [...acc, el]);\n}\n\n\n// let us test if indeed the function detects java array\nvar ArrayJava = Java.type('java.lang.String[]')\n\nvar javaArray = new ArrayJava(3);\njavaArray[0] = 'a'\njavaArray[1] = 'b'\njavaArray[2] = 'c'\n\nvar jsArray = as_js_array(javaArray)\nconsole.log(jsArray)\nconsole.log(jsArray.reduce((acc, el) =\u003e acc + el, \"\"))\n\n// let us test if indeed the function detects js array\nvar nativeJsArray = [ 'a', 'b', 'c' ]\nvar js2JsArray = as_js_array([ 'a', 'b', 'c' ])\nconsole.log(js2JsArray)\nconsole.log(js2JsArray.reduce((acc, el) =\u003e acc + el, \"\"))\n\n// original code, only changing the `Stream.of(s.split)` to  `as_js_array(s.split)`\n// and adapting the API, some `instead` of `filter`\nvar namesList = java.util.List.of(\"te test st\",\"test1\");\nnamesList.stream()\n\t.findFirst()\n\t.map(s =\u003e as_js_array(s.split(' ')).some(el =\u003e el === 'test'))\n```\n\nThe sample log output (ie, ignoring `console.debug`):\n\n```txt\na,b,c\nabc\na,b,c\nabc\nOptional[true]\n```\n\nin both profiles `-Pgraalvm20` and `-Pgraalvm24`. The `console.debug` will allow one to easily identify when the array was treated as a JS array or as a Java array. The full output for `-Pgraalvm20`:\n\n```txt\nyep, this is java, transforming to js array\na,b,c\nabc\nnot java\na,b,c\nabc\nnot java\nOptional[true]\n```\n\nThe full output for `-Pgraalvm24`:\n\n```txt\nyep, this is java, transforming to js array\na,b,c\nabc\nnot java\na,b,c\nabc\nnot java\nOptional[true]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeffque%2Fgraalvm-regression","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeffque%2Fgraalvm-regression","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeffque%2Fgraalvm-regression/lists"}