mirror of
https://github.com/tiennm99/lombok.git
synced 2026-08-11 00:25:23 +00:00
Fixed bug in reading long and double values
This commit is contained in:
@@ -214,6 +214,7 @@ public class ClassFileMetaData {
|
||||
* Checks if the constant pool contains the provided string constant, which implies the constant is used somewhere in the code.
|
||||
*
|
||||
* NB: String literals get concatenated by the compiler.
|
||||
* NB2: This method does NOT do any kind of normalization.
|
||||
*/
|
||||
public boolean containsStringConstant(String value) {
|
||||
int index = findUtf8(value);
|
||||
@@ -282,25 +283,23 @@ public class ClassFileMetaData {
|
||||
|
||||
private long readLong(int index) {
|
||||
int pos = offsets[index];
|
||||
return ((long)read32(pos)) << 32 | read32(pos + 4);
|
||||
return ((long)read32(pos)) << 32 | (read32(pos + 4) & 0x00000000FFFFFFFFL);
|
||||
}
|
||||
|
||||
private double readDouble(int index) {
|
||||
int pos = offsets[index];
|
||||
long bits = ((long)read32(pos)) << 32 | (read32(pos + 4) & 0x00000000FFFFFFFF);
|
||||
return Double.longBitsToDouble(bits);
|
||||
return Double.longBitsToDouble(readLong(index));
|
||||
}
|
||||
|
||||
private long readInteger(int index) {
|
||||
private int readInteger(int index) {
|
||||
return read32(offsets[index]);
|
||||
}
|
||||
|
||||
private float readFloat(int index) {
|
||||
return Float.intBitsToFloat(read32(offsets[index]));
|
||||
return Float.intBitsToFloat(readInteger(index));
|
||||
}
|
||||
|
||||
private int read32(int pos) {
|
||||
return (byteCode[pos] & 0xFF) << 24 | (byteCode[pos + 1] & 0xFF) << 16 | (byteCode[pos + 2] & 0xFF) << 8 | (byteCode[pos + 3] &0xFF);
|
||||
return (byteCode[pos] & 0xFF) << 24 | (byteCode[pos + 1] & 0xFF) << 16 | (byteCode[pos + 2] & 0xFF) << 8 | (byteCode[pos + 3] & 0xFF);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
public class Foo implements java.util.RandomAccess {
|
||||
private static final long LONG = 123L;
|
||||
private static final String ONE = "Eén";
|
||||
private static final long LONG_OVERFLOW = 0x1FFFFFFFFL;
|
||||
private static final String ONE = "E\u00e9n";
|
||||
private static final int INT = 123;
|
||||
private static final double DOUBLE = 1.23;
|
||||
private static final double DOUBLE_NAN = Double.NaN;
|
||||
|
||||
@@ -169,6 +169,7 @@ public class TestClassFileMetaData {
|
||||
@Test
|
||||
public void testContainsLong() {
|
||||
assertTrue(foo.containsLong(123));
|
||||
assertTrue(foo.containsLong(0x1FFFFFFFFL));
|
||||
|
||||
assertFalse(foo.containsLong(1));
|
||||
assertFalse(buux.containsLong(1));
|
||||
|
||||
Reference in New Issue
Block a user