Azure / Azure/azure-documentdb-java

NullPointerException on readDocument()

Offen
#112 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Java
Sterne
51
Forks
52
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

SDK Version: 1.16.0

We see following errors in logs:
```
java.lang.NullPointerException: null
at com.microsoft.azure.documentdb.internal.SessionContainer.compareAndSetToken(SessionContainer.java:194)
at com.microsoft.azure.documentdb.internal.SessionContainer.setSessionToken(SessionContainer.java:167)
at com.microsoft.azure.documentdb.internal.SessionContainer.setSessionToken(SessionContainer.java:156)
at com.microsoft.azure.documentdb.internal.SessionTokenHelper.captureSessionToken(SessionTokenHelper.java:138)
at com.microsoft.azure.documentdb.DocumentClient.captureSessionToken(DocumentClient.java:3155)
at com.microsoft.azure.documentdb.DocumentClient.doRead(DocumentClient.java:3054)
at com.microsoft.azure.documentdb.DocumentClient.readDocument(DocumentClient.java:1041)
at com.tomtom.lns.batch.dao.CosmosDBDao.getDocumentByBatchId(CosmosDBDao.java:358)
```
```
java.lang.NullPointerException: null
at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936)
at com.microsoft.azure.documentdb.internal.SessionContainer.getPartitionKeyRangeIdToTokenMap(SessionContainer.java:72)
at com.microsoft.azure.documentdb.internal.SessionContainer.resolveGlobalSessionToken(SessionContainer.java:88)
at com.microsoft.azure.documentdb.internal.SessionContainer.resolveGlobalSessionToken(SessionContainer.java:84)
at com.microsoft.azure.documentdb.DocumentClient.applySessionToken(DocumentClient.java:3143)
at com.microsoft.azure.documentdb.DocumentClient.doRead(DocumentClient.java:3051)
at com.microsoft.azure.documentdb.DocumentClient.readDocument(DocumentClient.java:1041)
at com.tomtom.lns.batch.dao.CosmosDBDao.getDocumentByBatchId(CosmosDBDao.java:358)
```

Our retrieve method:
```java
private Document getDocumentByBatchId(final DocumentClient client, final BatchId batchId) {
try {
final RequestOptions requestOptions = new RequestOptions();
requestOptions.setPartitionKey(new PartitionKey(batchId.getUuid().toString()));
requestOptions.setConsistencyLevel(ConsistencyLevel.Strong);
return client.readDocument(getBatchDocumentLink(batchId), requestOptions).getResource();
} catch (DocumentClientException e) {
if (e.getStatusCode() == HttpStatus.NOT_FOUND.value()) {
throw new BatchNotFoundException(batchId);
}
throw new IllegalStateException("Cannot fetch Batch document: " + batchId, e);
}
}
```

And for clarity getBatchDocumentLink() method:
```java
private static final String BATCH_DOCUMENT_LINK_TEMPLATE = "/dbs/BatchDB/colls/batches/docs/%s"
...
private String getBatchDocumentLink(final BatchId batchId) {
return String.format(BATCH_DOCUMENT_LINK_TEMPLATE, batchId.getUuid().toString());
}
```

Our DocumentClient is created by:
```java
private DocumentClient createDocumentClient(final String url, final String masterKey,
final ImmutableList preferredLocations) {
final ConnectionPolicy connectionPolicy = new ConnectionPolicy();
connectionPolicy.setEnableEndpointDiscovery(true);
connectionPolicy.setConnectionMode(ConnectionMode.DirectHttps);
connectionPolicy.setMaxPoolSize(CONNECTION_POOL_SIZE);
connectionPolicy.setPreferredLocations(preferredLocations);
return new DocumentClient(url, masterKey, connectionPolicy, ConsistencyLevel.Session);
}
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit SessionContainer.java in den Zeilen 72, 88, 167 und 194 und verfolge dann die Verarbeitung des session-token von DocumentClient.readDocument() durch die Zeilen 3051–3155 von DocumentClient.java. Reproduziere den gemeldeten Lesevorgang mit einem partition key, strong consistency und der gezeigten client configuration; erledigt ist die Aufgabe, wenn der Lesevorgang keinen der beiden NullPointerException-Pfade mehr auslöst und das Verhalten durch Regressionstests abgedeckt ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
azure, java
Bereich
databases
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
38/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.