Skip to content

Commit 4a52268

Browse files
committed
DATACOUCH-604 - Fix NPE when looking for Id field in interface.
This was failing with a repository for the domain object CouchbaseOAuth2AccessToken. The following dependency is needed. <dependency> <groupId>org.springframework.security.oauth</groupId> <artifactId>spring-security-oauth2</artifactId> <version>2.4.1.RELEASE</version> </dependency> package org.springframework.data.couchbase.domain; import org.springframework.data.annotation.Id; import org.springframework.data.couchbase.core.mapping.Document; import org.springframework.data.couchbase.core.mapping.Field; import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; import org.springframework.security.oauth2.common.OAuth2AccessToken; @document(expiry = 30 * 24 * 60 * 60) public class CouchbaseOAuth2AccessToken extends DefaultOAuth2AccessToken { private static final long serialVersionUID = 6537949925775752989L; @id private String tokenId; @field private String authentication; @field private String authenticationKey; @field private String clientId; @field private String userName; // getters and setters omitted for brevity private CouchbaseOAuth2AccessToken() { this((String) null); } public CouchbaseOAuth2AccessToken(OAuth2AccessToken accessToken) { super(accessToken); this.tokenId = accessToken.getValue(); } public CouchbaseOAuth2AccessToken(String value) { super(value); this.tokenId = value; } }
1 parent 07c28fe commit 4a52268

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/main/java/org/springframework/data/couchbase/core/mapping/BasicCouchbasePersistentProperty.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.data.couchbase.core.mapping;
1818

19-
import org.springframework.data.annotation.Id;
2019
import org.springframework.data.mapping.Association;
2120
import org.springframework.data.mapping.MappingException;
2221
import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty;
@@ -28,8 +27,6 @@
2827

2928
import com.couchbase.client.core.deps.com.fasterxml.jackson.annotation.JsonProperty;
3029

31-
import java.util.Locale;
32-
3330
/**
3431
* Implements annotated property representations of a given {@link Field} instance.
3532
* <p/>
@@ -99,7 +96,13 @@ public String getFieldName() {
9996
// DATACOUCH-145: allows SDK's @Id annotation to be used
10097
@Override
10198
public boolean isIdProperty() {
102-
return isAnnotationPresent(Id.class) || super.isIdProperty()
103-
|| this.getFieldName().toLowerCase(Locale.ROOT).equals("id");
99+
if (super.isIdProperty()){
100+
return true;
101+
}
102+
// is field named "id"
103+
if(getName().equals("id")){
104+
return true;
105+
}
106+
return false;
104107
}
105108
}

0 commit comments

Comments
 (0)