Skip to content

Commit

Permalink
fix(jans-auth-server): fixed index during list joins and npe on nextI…
Browse files Browse the repository at this point in the history
…ndex.

#8562
Signed-off-by: YuriyZ <yzabrovarniy@gmail.com>
  • Loading branch information
yuriyz committed Jun 7, 2024
1 parent 607cb03 commit 63ab6b6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package io.jans.as.server.service.token;

import java.util.concurrent.locks.ReentrantLock;

import io.jans.as.server.model.config.ConfigurationFactory;
import io.jans.as.server.service.cluster.TokenPoolService;
import io.jans.model.token.TokenPool;
import io.jans.util.Pair;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

import java.util.concurrent.locks.ReentrantLock;

/**
* @author Yuriy Z
* @author Yuriy Movchan
Expand All @@ -35,7 +35,7 @@ public Pair<Integer, TokenPool> nextIndex() {
if (localTokenPool != null) {
newIndex = localTokenPool.nextIndex();
if (newIndex != -1) {
return new Pair<Integer, TokenPool>(newIndex, localTokenPool);
return new Pair<>(newIndex, localTokenPool);
}
}

Expand All @@ -46,20 +46,21 @@ public Pair<Integer, TokenPool> nextIndex() {
if (System.identityHashCode(localTokenPool) != System.identityHashCode(tokenPool)) {
// Try to get index from new pool which another threads gets already
localTokenPool = tokenPool;
newIndex = localTokenPool.nextIndex();
if (newIndex != -1) {
return new Pair<Integer, TokenPool>(newIndex, localTokenPool);
}
if (localTokenPool != null) {
newIndex = localTokenPool.nextIndex();
if (newIndex != -1) {
return new Pair<>(newIndex, localTokenPool);
}
}
}

// Allocate new ToeknPool
tokenPool = tokenPoolService.allocate(configurationFactory.getNodeId());

newIndex = tokenPool.nextIndex();
return new Pair<Integer, TokenPool>(newIndex, tokenPool);
return new Pair<>(newIndex, tokenPool);
} finally {
allocatedLock.unlock();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public StatusList join(List<TokenPool> pools) {
try {
StatusList poolStatusList = StatusList.fromEncoded(pool.getData(), bitSize);
for (int i = 0; i < poolStatusList.getBitSetLength(); i++) {
result.set(pool.getId() + i, poolStatusList.get(i));
result.set(pool.getStartIndex() + i, poolStatusList.get(i));
}

} catch (Exception e) {
Expand Down

0 comments on commit 63ab6b6

Please sign in to comment.