# Painless script throws "illegal tree structure." when using literal with hexadecimal value

**URL:** <https://discuss.elastic.co/t/painless-script-throws-illegal-tree-structure-when-using-literal-with-hexadecimal-value/310007>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [July 19, 2022, 11:24am UTC](https://discuss.elastic.co/t/painless-script-throws-illegal-tree-structure-when-using-literal-with-hexadecimal-value/310007 "2022-07-19T11:24:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nimrod\_Karni](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nimrod_karni/32/33770_2.png) [@Nimrod\_Karni](https://discuss.elastic.co/u/Nimrod_Karni)\
**Post date:** [July 19, 2022, 11:24am UTC](https://discuss.elastic.co/t/painless-script-throws-illegal-tree-structure-when-using-literal-with-hexadecimal-value/310007/1 "2022-07-19T11:24:50Z")

</div>

Elasticsearch 8.3  
Using painless Lab (Kibana 8.3)

> ```auto
> byte i = 0xc;
> return i;
> 
> ```

Works fine - output 12

> ```auto
> byte i = 0xd;
> return i;
> 
> ```

output -  
Unhandled Exception illegal\_state\_exception  
Illegal tree structure.

should be 13.

---

<div class="post-metadata">

**Author:** ![stu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stu/32/75063_2.png) [@stu](https://discuss.elastic.co/u/stu)\
**Post date:** [July 19, 2022, 2:42pm UTC](https://discuss.elastic.co/t/painless-script-throws-illegal-tree-structure-when-using-literal-with-hexadecimal-value/310007/2 "2022-07-19T14:42:00Z")

</div>

Hi @Nimrod_Karni, you're right that's a bug. For now, avoid using those literals.

You can track the issue here:

> <https://github.com/elastic/elasticsearch/issues/88614>
>
> If a hex literal has an 'd' of 'f' in it, such as '0xf' or '0xd', the compiler f…ails with illegal tree structure.
> 
> The other hex literals work. The issue is probably related to using \`f\` and \`d\` in float and double literals.
> 
> \`\`\`
> public void testHexCollisionDouble() {
> assertEquals(13, exec("return 0xd"));
> }
> 
> public void testHexCollisionFloat() {
> assertEquals(15, exec("return 0xf"));
> }
> 
> public void testHex() throws Exception {
> for (int i = 0; i \<= 15; i++) {
> String hex = Integer.toHexString(i);
> if ("d".equals(hex) || "f".equals(hex)) {
> continue;
> }
> assertEquals(i, exec("return 0x" + hex));
> assertEquals(i, exec("return 0x" + hex.toUpperCase(Locale.ROOT)));
> assertEquals(i, exec("return 0X" + hex));
> assertEquals(i, exec("return 0X" + hex.toUpperCase(Locale.ROOT)));
> }
> }
> \`\`\`

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 16, 2022, 2:42pm UTC](https://discuss.elastic.co/t/painless-script-throws-illegal-tree-structure-when-using-literal-with-hexadecimal-value/310007/3 "2022-08-16T14:42:49Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
