Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-130550

Use @NonNull and @Nullable annotations on Android code

    XMLWordPrintable

Details

    • User Story
    • Resolution: Unresolved
    • P1: Critical
    • 6.9
    • 6.9
    • QPA: Android
    • None
    • Android
    • 2024wk42s3FOQtforAndroid, 2024wk44s3FOQtforAndroid

    Description

      Qt Android Java code is growing bigger and bigger while maintaining some legacy code, and it's becoming harder and harder to avoid code usage that might lead to cases of using null objects after being missed in reviews. So, we get some bugs related to exceptions of bad usage of null objects.

      Java has annotations like @NonNull and @Nullable (or even @NotNull):

      • javax.annotation.Nonnull or javax.validation.constraints.NotNull
      • }}{{org.jetbrains.annotations.NotNull
      • org.eclipse.jdt.annotation.NonNull{}
      • android.support.annotation.NonNull
      • and of course androidx.annotation.NonNull

      And there are static analysis frameworks that help spot bad null-ness usage (with their own set of @NonNull and @Nullable annotations){}

      Build and linte

      • Gradle handles dependencies by default if used, it might require internet access first time
        • [!] Look into caching common dependencies?
      • javac and custom linter setup
      • A static analysis framework that handles linter under the hood

      Which is the right one to use

      Of course at the end we need to go with one option, that can also be integrated to the CI. Using some of the static analysis frameworks might offer more than null-ness checks, however, it would be foreign to Android, and might just brings our code away from Android style code.

      On the other hand using anything other than a framework, would require us to provide our own linter to work with javac and fail on such cases.

      Using Gradle, would be the most ideal option, which would also open the door to use more than androidx annotations, however, we need to figure out the case of offline builds.

      **

       

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              assam Assam Boudjelthia
              assam Assam Boudjelthia
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes