Skip to content

Commit 5391d11

Browse files
authored
Merge pull request #5162 from realm/merge-39bb67-to-master-4.0
Fix merge from 39bb67 to master-4.0
2 parents a19d9fb + b27e898 commit 5391d11

71 files changed

Lines changed: 2010 additions & 2073 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,20 @@ and `SyncUser#retrieveInfoForUserAsync` which returns a `SyncUserInfo` with mode
5151
* [ObjectServer] APIs of `UserStore` have been changed to support same user identity but different authentication server scenario.
5252
* [ObjectServer] Added `SyncUser.allSessions` to retrieve the all valid sessions belonging to the user (#4783).
5353
* Added `Nullable` annotation to methods that may return `null` in order to improve Kotlin usability. This also introduced a dependency to `com.google.code.findbugs:jsr305`.
54+
* `org.jetbrains.annotations.NotNull` is now an alias for `@Required`. This means that the Realm Schema now fully understand Kotlin non-null types.
5455
* Added support for new data type `MutableRealmIntegers`. The new type behaves almost exactly as a reference to a Long (mutable nullable, etc) but supports `increment` and `decrement` methods, which implement a Conflict Free Replicated Data Type, whose value will converge even when changed across distributed devices with poor connections (#4266).
56+
* Added more detailed exception message for `RealmMigrationNeeded`.
57+
* Bumping schema version only without any actual schema changes will just succeed even when the migration block is not supplied. It threw an `RealmMigrationNeededException` before in the same case.
58+
* Throw `IllegalStateException` when schema validation fails because of wrong declaration of `@LinkingObjects`.
5559

5660
### Bug Fixes
5761

5862
### Internal
63+
5964
* [ObjectServer] removed `ObjectServerUser` and its inner classes, in a step to reduce `SyncUser` complexity (#3741).
6065
* [ObjectServer] changed the `SyncSessionStopPolicy` to `AfterChangesUploaded` to align with other binding and to prevent use cases where the Realm might be deleted before the last changes get synchronized (#5028).
61-
6266
* Upgraded Realm Sync to 1.10.8
67+
* Let Object Store handle migration.
6368

6469
## 3.5.1 (YYYY-MM-DD)
6570

realm/realm-annotations-processor/src/main/java/io/realm/processor/ClassMetaData.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Set;
2626

2727
import javax.annotation.processing.ProcessingEnvironment;
28+
import javax.lang.model.element.AnnotationMirror;
2829
import javax.lang.model.element.Element;
2930
import javax.lang.model.element.ElementKind;
3031
import javax.lang.model.element.ExecutableElement;
@@ -375,7 +376,7 @@ private boolean categorizeField(Element element) {
375376
if (!categorizeIndexField(element, field)) { return false; }
376377
}
377378

378-
if (field.getAnnotation(Required.class) != null) {
379+
if (isRequiredField(field)) {
379380
categorizeRequiredField(element, field);
380381
} else {
381382
// The field doesn't have the @Required annotation.
@@ -408,6 +409,23 @@ private boolean categorizeField(Element element) {
408409
return true;
409410
}
410411

412+
private boolean isRequiredField(VariableElement field) {
413+
if (field.getAnnotation(Required.class) != null) {
414+
return true;
415+
}
416+
417+
// Kotlin uses the `org.jetbrains.annotations.NotNull` annotation to mark non-null fields.
418+
// In order to fully support the Kotlin type system we interpret `@NotNull` as an alias
419+
// for `@Required`
420+
for (AnnotationMirror annotation : field.getAnnotationMirrors()) {
421+
if (annotation.getAnnotationType().toString().equals("org.jetbrains.annotations.NotNull")) {
422+
return true;
423+
}
424+
}
425+
426+
return false;
427+
}
428+
411429
// The field has the @Index annotation. It's only valid for column types:
412430
// STRING, DATE, INTEGER, BOOLEAN, and RealmMutableInteger
413431
private boolean categorizeIndexField(Element element, VariableElement variableElement) {
@@ -441,13 +459,13 @@ private boolean categorizeIndexField(Element element, VariableElement variableEl
441459
private void categorizeRequiredField(Element element, VariableElement variableElement) {
442460
if (Utils.isPrimitiveType(variableElement)) {
443461
Utils.error(String.format(Locale.US,
444-
"@Required annotation is unnecessary for primitive field \"%s\".", element));
462+
"@Required or @NotNull annotation is unnecessary for primitive field \"%s\".", element));
445463
return;
446464
}
447465

448-
if (Utils.isRealmList(variableElement) || Utils.isRealmModel(variableElement)) {
466+
if (Utils.isRealmModel(variableElement)) {
449467
Utils.error(String.format(Locale.US,
450-
"Field \"%s\" with type \"%s\" cannot be @Required.", element, element.asType()));
468+
"Field \"%s\" with type \"%s\" cannot be @Required or @NotNull.", element, element.asType()));
451469
return;
452470
}
453471

0 commit comments

Comments
 (0)