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