3

I am using a Java decompiler and it seems to give a sensible code, except that it gives strange symbols for constant integers. For example:

#int[] arr = new int['田'];

This symbol has a numeric value in U+7530. I wonder if it works to revert this symbol back to its numeric value or I can't rely on this mechanism?

My problem is that this code gives an array-out-of-bound exception, so tuning the sizes of the arrays is quite important.

Tsundoku
  • 2,455
  • 1
  • 19
  • 31
D.Badawi
  • 175
  • 1
  • 13
  • You didn't give your OS. A guess is that you have the OS locale set to one that needs full unicode. If so, setting to US or another English-speaking one may cause constants to resolve to integers rather than unicode characters. – Gene Jul 26 '16 at 15:58
  • 1
    Note that `(int) '田' == 30000`; since array indexes are always integers, it makes no difference whether you use `'田'` or `30000`. – Andy Turner Jul 26 '16 at 16:13
  • Thank you. Now it makes sense. – D.Badawi Jul 26 '16 at 16:25
  • @Badawi, What is the solution you took for this situation, some of our .class files is having the similar type of issues that it shown as some special character when the subscript is of 3 digits, but 4 digit numbers are just fine – rinilnath Nov 20 '19 at 05:33

1 Answers1

0

At the bytecode level, local variables have no distinction between booleans, bytes, chars, shorts, and ints. Everything is just compiled to ints under the hood, with truncation instructions inserted where appropriate.

This means that the decompiler has to arbitrarily decide on which type to decompile it to (assuming there is no debug metadata). It looks like your decompiler decided to decompile the integer constant to a character constant instead.

Antimony
  • 37,781
  • 10
  • 100
  • 107
  • IS there any other decompiler that does not do so like treating numeric constant as character constant ? – rinilnath Nov 20 '19 at 05:35
  • The Krakatau decompiler won't output character literals if that's what you're asking. https://github.com/Storyyeller/Krakatau – Antimony Nov 20 '19 at 19:08