View Javadoc
1   /*
2    * Copyright (C) 2015, Google Inc.
3    * and other copyright owners as documented in the project's IP log.
4    *
5    * This program and the accompanying materials are made available
6    * under the terms of the Eclipse Distribution License v1.0 which
7    * accompanies this distribution, is reproduced below, and is
8    * available at http://www.eclipse.org/org/documents/edl-v10.php
9    *
10   * All rights reserved.
11   *
12   * Redistribution and use in source and binary forms, with or
13   * without modification, are permitted provided that the following
14   * conditions are met:
15   *
16   * - Redistributions of source code must retain the above copyright
17   *   notice, this list of conditions and the following disclaimer.
18   *
19   * - Redistributions in binary form must reproduce the above
20   *   copyright notice, this list of conditions and the following
21   *   disclaimer in the documentation and/or other materials provided
22   *   with the distribution.
23   *
24   * - Neither the name of the Eclipse Foundation, Inc. nor the
25   *   names of its contributors may be used to endorse or promote
26   *   products derived from this software without specific prior
27   *   written permission.
28   *
29   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
30   * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
31   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
32   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
38   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42   */
43  
44  package org.eclipse.jgit.annotations;
45  
46  import static java.lang.annotation.ElementType.FIELD;
47  import static java.lang.annotation.ElementType.LOCAL_VARIABLE;
48  import static java.lang.annotation.ElementType.METHOD;
49  import static java.lang.annotation.ElementType.PARAMETER;
50  
51  import java.lang.annotation.Documented;
52  import java.lang.annotation.Retention;
53  import java.lang.annotation.RetentionPolicy;
54  import java.lang.annotation.Target;
55  
56  /**
57   * Marks types that can hold the value {@code null} at run time.
58   * <p>
59   * Unlike {@code org.eclipse.jdt.annotation.Nullable}, this has run-time
60   * retention, allowing the annotation to be recognized by
61   * <a href="https://github.com/google/guice/wiki/UseNullable">Guice</a>. Unlike
62   * {@code javax.annotation.Nullable}, this does not involve importing new classes
63   * to a standard (Java EE) package, so it can be deployed in an OSGi container
64   * without running into
65   * <a href="http://wiki.osgi.org/wiki/Split_Packages">split-package</a>
66   * <a href="https://gerrit-review.googlesource.com/50112">problems</a>.
67   * <p>
68   * You can use this annotation to qualify a type in a method signature or local
69   * variable declaration. The entity whose type has this annotation is allowed to
70   * hold the value {@code null} at run time. This allows annotation based null
71   * analysis to infer that
72   * <ul>
73   * <li>Binding a {@code null} value to the entity is legal.
74   * <li>Dereferencing the entity is unsafe and can trigger a
75   * {@code NullPointerException}.
76   * </ul>
77   * <p>
78   * To avoid a dependency on Java 8, this annotation does not use
79   * {@link Target @Target} {@code TYPE_USE}. That may change when JGit starts
80   * requiring Java 8.
81   * <p>
82   * <b>Warning:</b> Please do not use this annotation on arrays. Different
83   * annotation processors treat {@code @Nullable Object[]} differently: some
84   * treat it as an array of nullable objects, for consistency with versions of
85   * {@code Nullable} defined with {@code @Target} {@code TYPE_USE}, while others
86   * treat it as a nullable array of objects. JGit therefore avoids using this
87   * annotation on arrays altogether.
88   *
89   * @see <a href=
90   *      "http://types.cs.washington.edu/checker-framework/current/checker-framework-manual.html#faq-array-syntax-meaning">
91   *      The checker-framework manual</a>
92   * @since 4.2
93   */
94  @Documented
95  @Retention(RetentionPolicy.RUNTIME)
96  @Target({ FIELD, METHOD, PARAMETER, LOCAL_VARIABLE })
97  public @interface Nullable {
98  	// marker annotation with no members
99  }