Skip to content

Commit

Permalink
fix(Android): Executing transaction fails at runtime (#2100)
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Ivanov <[email protected]>
  • Loading branch information
0xivanov authored Nov 28, 2024
1 parent dff3bef commit d88f7b4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
12 changes: 1 addition & 11 deletions sdk/src/main/java/com/hedera/hashgraph/sdk/BaseNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -363,18 +363,8 @@ synchronized void close(Duration timeout) throws InterruptedException {
* @return the user agent string
*/
private String getUserAgent() {
var theModule = getClass().getModule();
var thePackage = getClass().getPackage();
String implementationVersion;
if (theModule.getName() == null) {
// running on classpath
implementationVersion =
thePackage != null ? thePackage.getImplementationVersion() : null;
} else {
// running on module path
implementationVersion =
theModule.getDescriptor().version().map(ModuleDescriptor.Version::toString).orElse(null);
}
var implementationVersion = thePackage != null ? thePackage.getImplementationVersion() : null;
return "hedera-sdk-java/" + ((implementationVersion != null) ? ("v" + implementationVersion) : "DEV");
}
}
5 changes: 3 additions & 2 deletions sdk/src/main/java/com/hedera/hashgraph/sdk/TransactionId.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Objects;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.BiConsumer;
Expand Down Expand Up @@ -69,7 +70,6 @@ public final class TransactionId implements Comparable<TransactionId> {

private static final long NANOSECONDS_TO_REMOVE = 10000000000L;

private static final Random randomNanosecs = new Random();
private static final AtomicLong monotonicTime = new AtomicLong();


Expand Down Expand Up @@ -128,7 +128,8 @@ public static TransactionId generate(AccountId accountId) {
}
} while (!monotonicTime.compareAndSet(lastTime, currentTime));

return new TransactionId(accountId, Instant.ofEpochSecond(0, currentTime + randomNanosecs.nextLong(1_000)));
// NOTE: using ThreadLocalRandom because it's compatible with Android SDK version 26
return new TransactionId(accountId, Instant.ofEpochSecond(0, currentTime + ThreadLocalRandom.current().nextLong(1_000)));
}

/**
Expand Down

0 comments on commit d88f7b4

Please sign in to comment.