Skip to content

Commit 4e41bc9

Browse files
jeet1995Copilot
andcommitted
Address Copilot review: fix 3 missed static final fields, long lines, stale docs
- Removed remaining static final accessor fields in DocumentQueryExecutionContextFactory, CosmosQueryRequestOptionsBase, CosmosQueryRequestOptionsImpl - Extracted local variables for long inline accessor chains in SessionTokenMismatchRetryPolicy, RxDocumentClientImpl, CosmosPagedFluxDefaultImpl - Updated test Javadoc to reflect lazy accessor approach (not Class.forName) - Reduced child JVM runs from 3 to 1 (invocationCount=5 provides repetition) - Fixed CHANGELOG PR link to #48689 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 95e43c4 commit 4e41bc9

File tree

8 files changed

+97
-65
lines changed

8 files changed

+97
-65
lines changed

sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/ImplementationBridgeHelpersTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public void concurrentAccessorInitializationShouldNotDeadlock() throws Exception
148148
command.add(ConcurrentClinitChildProcess.class.getName());
149149

150150
int timeoutSeconds = 30;
151-
int runs = 3;
151+
int runs = 1;
152152

153153
for (int run = 1; run <= runs; run++) {
154154
final int currentRun = run;
@@ -286,15 +286,15 @@ public static void main(String[] args) {
286286
}
287287

288288
/**
289-
* Enforces that every class targeted by {@code ensureClassInitialized()} in
289+
* Enforces that every {@code *Helper} inner class in
290290
* {@link ImplementationBridgeHelpers} registers its accessor during {@code <clinit>}
291291
* (i.e., has a {@code static { initialize(); }} block).
292292
* <p>
293293
* Verification is behavioral, not source-based: a forked child JVM iterates every
294-
* {@code *Helper} inner class, calls each {@code getXxxAccessor()} getter (which triggers
295-
* {@code Class.forName()} → {@code <clinit>}), and checks the accessor is non-null
296-
* via reflection. If a class is missing {@code static { initialize(); }}, the accessor
297-
* remains null and this test fails.
294+
* {@code *Helper} inner class, calls each {@code getXxxAccessor()} getter (which
295+
* lazily resolves the accessor), and checks the accessor is non-null via reflection.
296+
* If a class is missing {@code static { initialize(); }}, the accessor remains null
297+
* and this test fails.
298298
*/
299299
@Test(groups = { "unit" })
300300
public void allAccessorClassesMustHaveStaticInitializerBlock() throws Exception {
@@ -361,8 +361,8 @@ public void allAccessorClassesMustHaveStaticInitializerBlock() throws Exception
361361
public static final class AccessorRegistrationChildProcess {
362362
public static void main(String[] args) throws Exception {
363363
// Iterate all *Helper inner classes in ImplementationBridgeHelpers.
364-
// For each, call the getXxxAccessor() getter which triggers ensureClassInitialized()
365-
// → Class.forName() → <clinit>. Then verify the accessor field is non-null.
364+
// For each, call the getXxxAccessor() getter which lazily resolves the
365+
// accessor (triggering <clinit> if needed). Then verify the accessor field is non-null.
366366

367367
Class<?>[] helpers = ImplementationBridgeHelpers.class.getDeclaredClasses();
368368
List<String> failures = new ArrayList<>();
@@ -396,10 +396,10 @@ public static void main(String[] args) throws Exception {
396396
continue;
397397
}
398398

399-
// Find the target class name by looking for a getXxxAccessor method that calls
400-
// ensureClassInitialized. We can't easily extract the string constant, so instead
399+
// Find the target class name by looking for a getXxxAccessor method that lazily
400+
// resolves the accessor. We can't easily extract the string constant, so instead
401401
// we call the getter and check if the accessor becomes non-null.
402-
// The getter calls ensureClassInitialized() → Class.forName() → <clinit>.
402+
// The getter lazily triggers <clinit> of the target class if needed.
403403
// If <clinit> calls initialize(), the accessor is registered.
404404
java.lang.reflect.Method getterMethod = null;
405405
for (java.lang.reflect.Method m : helper.getDeclaredMethods()) {

sdk/cosmos/azure-cosmos/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#### Bugs Fixed
1010
* Fixing an NPE caused due to boxed Boolean conversion. - See [PR 48656](https://github.com/Azure/azure-sdk-for-java/pull/48656/)
11-
* Fixed JVM `<clinit>` deadlock when multiple threads concurrently trigger Cosmos SDK class loading for the first time. - See [PR 48667](https://github.com/Azure/azure-sdk-for-java/pull/48667)
11+
* Fixed JVM `<clinit>` deadlock when multiple threads concurrently trigger Cosmos SDK class loading for the first time. - See [PR 48689](https://github.com/Azure/azure-sdk-for-java/pull/48689)
1212

1313
#### Other Changes
1414

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/CosmosQueryRequestOptionsBase.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
* in the Azure Cosmos DB database service.
3030
*/
3131
public abstract class CosmosQueryRequestOptionsBase<T extends CosmosQueryRequestOptionsBase<?>> implements OverridableRequestOptions {
32-
private final static ImplementationBridgeHelpers.CosmosDiagnosticsThresholdsHelper.CosmosDiagnosticsThresholdsAccessor thresholdsAccessor =
33-
ImplementationBridgeHelpers.CosmosDiagnosticsThresholdsHelper.getCosmosDiagnosticsThresholdsAccessor();
34-
3532
private ConsistencyLevel consistencyLevel;
3633
private ReadConsistencyStrategy readConsistencyStrategy;
3734
private String sessionToken;
@@ -373,7 +370,9 @@ public Duration getThresholdForDiagnosticsOnTracer() {
373370
return CosmosDiagnosticsThresholds.DEFAULT_NON_POINT_OPERATION_LATENCY_THRESHOLD;
374371
}
375372

376-
return thresholdsAccessor.getNonPointReadLatencyThreshold(this.thresholds);
373+
return ImplementationBridgeHelpers.CosmosDiagnosticsThresholdsHelper
374+
.getCosmosDiagnosticsThresholdsAccessor()
375+
.getNonPointReadLatencyThreshold(this.thresholds);
377376
}
378377

379378
/**

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/CosmosQueryRequestOptionsImpl.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
import java.util.List;
1414

1515
public final class CosmosQueryRequestOptionsImpl extends CosmosQueryRequestOptionsBase<CosmosQueryRequestOptionsImpl> {
16-
private final static ImplementationBridgeHelpers.CosmosDiagnosticsThresholdsHelper.CosmosDiagnosticsThresholdsAccessor thresholdsAccessor =
17-
ImplementationBridgeHelpers.CosmosDiagnosticsThresholdsHelper.getCosmosDiagnosticsThresholdsAccessor();
1816
private String partitionKeyRangeId;
1917
private Boolean scanInQueryEnabled;
2018
private Boolean emitVerboseTracesInQuery;

0 commit comments

Comments
 (0)