Netflix / hollow

Hollow is a java library and toolset for disseminating in-memory datasets from a single producer to many consumers for high performance read-only access.
Apache License 2.0
1.2k stars 216 forks source link

Add nullability annotations to generated API #315

Open DanielThomas opened 5 years ago

DanielThomas commented 5 years ago

This is particularly useful for Kotlin interop, as it allows the compiler/inspections to infer nullability, but is supported in IntelliJ for several languages:

https://kotlinlang.org/docs/reference/java-interop.html#nullability-annotations

PaulSandoz commented 5 years ago

This relates to pull request #286. Supporting deprecation of a field or non-nullability requires some notion of a "modifier" on a hollow field and the ability to map from an annotation on the data model field to such a modifier. A mapping could be declared by the developer so they can use their non-null annotation du-jour.

DanielThomas commented 5 years ago

That'd work perfectly, as Kotlin adds the annotations automatically based on nullability information from the type.

That'd also need to extend to *PrimaryKeyIndex and similar generated classes.

PaulSandoz commented 5 years ago

Re: *PrimaryKeyIndex can you explain more?

DanielThomas commented 5 years ago

That is, the other place where nullability information would be useful is the generated PrimaryKeyIndexes:

    public ModuleDescriptor findMatch(String idOrganization, String idName, String idVersion, String idType) {
        int ordinal = idx.getMatchingOrdinal(idOrganization, idName, idVersion, idType);
        if(ordinal == -1)
            return null;
        return api.getModuleDescriptor(ordinal);
    }

In this case ModuleDescriptor is null if a match isn't found.