Character literals decompiled as number literals
CFR version
CFR 0.152-SNAPSHOT (050e735)
Compiler
javac 1.8.0_252
Description
Character literals decompiled as number literals which makes the code non-readable. For example '.' and '/' decompiled as 46 and 47.
Example
package test.test;
public class TestChar {
private static final String TEST = "src/Test.java";
public static void main(final String[] args) {
System.out.println(TEST.substring(TEST.indexOf('/') + 1, TEST.indexOf('.')));
}
}
Result
package test.test;
public class TestChar {
private static final String TEST = "src/Test.java";
public static void main(String[] arrstring) {
System.out.println(TEST.substring(TEST.indexOf(47) + 1, TEST.indexOf(46)));
}
}
Hey - yes, I can see that's annoying ... the pain here is - this is actually behaving technically as it should..... because the indexOf method doesn't take a char... it takes an int...
public int indexOf(int ch) {
return indexOf(ch, 0);
}
(I've no idea why, it's probably some odd historical thing, or to do with the fact that char type is too small for unicode characters...).
Edit : Ah yes, it's definitely because of unicode....
if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
// handle most cases here (ch is a BMP code point or a
// negative value (invalid code point))
Probably possible to hack together a special case for it, as I can see that it's liable to be a common place to put char constants, but not so much a bug as a ..... 'java should have better chars' ;)
See also https://github.com/nbauma109/jd-core-v0/blob/da9279904055a5a67fe35e95bda61f4723e71e56/src/main/java/jd/core/process/analyzer/classfile/visitor/SetConstantTypeInStringIndexOfMethodsVisitor.java#L190