You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Nullable.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (C) 2015, Google Inc. and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.annotations;
  11. import static java.lang.annotation.ElementType.FIELD;
  12. import static java.lang.annotation.ElementType.LOCAL_VARIABLE;
  13. import static java.lang.annotation.ElementType.METHOD;
  14. import static java.lang.annotation.ElementType.PARAMETER;
  15. import java.lang.annotation.Documented;
  16. import java.lang.annotation.Retention;
  17. import java.lang.annotation.RetentionPolicy;
  18. import java.lang.annotation.Target;
  19. /**
  20. * Marks types that can hold the value {@code null} at run time.
  21. * <p>
  22. * Unlike {@code org.eclipse.jdt.annotation.Nullable}, this has run-time
  23. * retention, allowing the annotation to be recognized by
  24. * <a href="https://github.com/google/guice/wiki/UseNullable">Guice</a>. Unlike
  25. * {@code javax.annotation.Nullable}, this does not involve importing new classes
  26. * to a standard (Java EE) package, so it can be deployed in an OSGi container
  27. * without running into
  28. * <a href="http://wiki.osgi.org/wiki/Split_Packages">split-package</a>
  29. * <a href="https://gerrit-review.googlesource.com/50112">problems</a>.
  30. * <p>
  31. * You can use this annotation to qualify a type in a method signature or local
  32. * variable declaration. The entity whose type has this annotation is allowed to
  33. * hold the value {@code null} at run time. This allows annotation based null
  34. * analysis to infer that
  35. * <ul>
  36. * <li>Binding a {@code null} value to the entity is legal.
  37. * <li>Dereferencing the entity is unsafe and can trigger a
  38. * {@code NullPointerException}.
  39. * </ul>
  40. * <p>
  41. * To avoid a dependency on Java 8, this annotation does not use
  42. * {@link Target @Target} {@code TYPE_USE}. That may change when JGit starts
  43. * requiring Java 8.
  44. * <p>
  45. * <b>Warning:</b> Please do not use this annotation on arrays. Different
  46. * annotation processors treat {@code @Nullable Object[]} differently: some
  47. * treat it as an array of nullable objects, for consistency with versions of
  48. * {@code Nullable} defined with {@code @Target} {@code TYPE_USE}, while others
  49. * treat it as a nullable array of objects. JGit therefore avoids using this
  50. * annotation on arrays altogether.
  51. *
  52. * @see <a href=
  53. * "http://types.cs.washington.edu/checker-framework/current/checker-framework-manual.html#faq-array-syntax-meaning">
  54. * The checker-framework manual</a>
  55. * @since 4.2
  56. */
  57. @Documented
  58. @Retention(RetentionPolicy.RUNTIME)
  59. @Target({ FIELD, METHOD, PARAMETER, LOCAL_VARIABLE })
  60. public @interface Nullable {
  61. // marker annotation with no members
  62. }