@@ -26,8 +26,9 @@ public class LexFloatClient {
2626 */
2727 public static final int LF_FAIL = 1 ;
2828
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 ));
3132 }
3233
3334 /**
@@ -264,18 +265,19 @@ public static String GetHostLicenseMetadata(String key) throws LexFloatClientExc
264265 public static HostLicenseMeterAttribute GetHostLicenseMeterAttribute (String name ) throws LexFloatClientException , UnsupportedEncodingException {
265266 int status ;
266267 LongByReference allowedUses = new LongByReference (0 );
268+ // These references can still hold the uint64_t values populated by the native function
267269 LongByReference totalUses = new LongByReference (0 );
268270 LongByReference grossUses = new LongByReference (0 );
269271
270272 if (Platform .isWindows ()) {
271273 status = LexFloatClientNative .GetHostLicenseMeterAttribute (new WString (name ), allowedUses , totalUses , grossUses );
272274 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 ()));
274276 }
275277 } else {
276278 status = LexFloatClientNative .GetHostLicenseMeterAttribute (name , allowedUses , totalUses , grossUses );
277279 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 ()));
279281 }
280282 }
281283 throw new LexFloatClientException (status );
0 commit comments