@@ -26,8 +26,9 @@ public class LexFloatClient {
26
26
*/
27
27
public static final int LF_FAIL = 1 ;
28
28
29
- private static long toUnsignedLong (long value ) {
30
- return BigInteger .valueOf (value ).and (BigInteger .valueOf (0xFFFFFFFFFFFFFFFFL )).longValue ();
29
+ // Convert long to BigInteger to correctly handle unsigned 64-bit values
30
+ private static BigInteger toUnsignedBigInteger (long value ) {
31
+ return BigInteger .valueOf (value ).and (BigInteger .valueOf (0xFFFFFFFFFFFFFFFFL ));
31
32
}
32
33
33
34
/**
@@ -264,18 +265,19 @@ public static String GetHostLicenseMetadata(String key) throws LexFloatClientExc
264
265
public static HostLicenseMeterAttribute GetHostLicenseMeterAttribute (String name ) throws LexFloatClientException , UnsupportedEncodingException {
265
266
int status ;
266
267
LongByReference allowedUses = new LongByReference (0 );
268
+ // These references can still hold the uint64_t values populated by the native function
267
269
LongByReference totalUses = new LongByReference (0 );
268
270
LongByReference grossUses = new LongByReference (0 );
269
271
270
272
if (Platform .isWindows ()) {
271
273
status = LexFloatClientNative .GetHostLicenseMeterAttribute (new WString (name ), allowedUses , totalUses , grossUses );
272
274
if (LF_OK == status ) {
273
- return new HostLicenseMeterAttribute (name , allowedUses .getValue (), toUnsignedLong (totalUses .getValue ()), toUnsignedLong (grossUses .getValue ()));
275
+ return new HostLicenseMeterAttribute (name , allowedUses .getValue (), toUnsignedBigInteger (totalUses .getValue ()), toUnsignedBigInteger (grossUses .getValue ()));
274
276
}
275
277
} else {
276
278
status = LexFloatClientNative .GetHostLicenseMeterAttribute (name , allowedUses , totalUses , grossUses );
277
279
if (LF_OK == status ) {
278
- return new HostLicenseMeterAttribute (name , allowedUses .getValue (), toUnsignedLong (totalUses .getValue ()), toUnsignedLong (grossUses .getValue ()));
280
+ return new HostLicenseMeterAttribute (name , allowedUses .getValue (), toUnsignedBigInteger (totalUses .getValue ()), toUnsignedBigInteger (grossUses .getValue ()));
279
281
}
280
282
}
281
283
throw new LexFloatClientException (status );
0 commit comments