001/*
002 * Copyright (C) 2005 The Guava Authors
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package com.google.common.testing;
018
019import static com.google.common.base.Preconditions.checkArgument;
020import static com.google.common.base.Preconditions.checkNotNull;
021
022import com.google.common.annotations.GwtIncompatible;
023import com.google.common.annotations.J2ktIncompatible;
024import com.google.common.base.Converter;
025import com.google.common.base.Objects;
026import com.google.common.collect.ClassToInstanceMap;
027import com.google.common.collect.ImmutableList;
028import com.google.common.collect.ImmutableSet;
029import com.google.common.collect.Lists;
030import com.google.common.collect.Maps;
031import com.google.common.collect.MutableClassToInstanceMap;
032import com.google.common.reflect.Invokable;
033import com.google.common.reflect.Parameter;
034import com.google.common.reflect.Reflection;
035import com.google.common.reflect.TypeToken;
036import com.google.errorprone.annotations.CanIgnoreReturnValue;
037import java.lang.annotation.Annotation;
038import java.lang.reflect.AnnotatedType;
039import java.lang.reflect.Constructor;
040import java.lang.reflect.InvocationTargetException;
041import java.lang.reflect.Member;
042import java.lang.reflect.Method;
043import java.lang.reflect.Modifier;
044import java.lang.reflect.ParameterizedType;
045import java.lang.reflect.Type;
046import java.lang.reflect.TypeVariable;
047import java.util.Arrays;
048import java.util.List;
049import java.util.concurrent.ConcurrentMap;
050import junit.framework.Assert;
051import junit.framework.AssertionFailedError;
052import org.checkerframework.checker.nullness.qual.Nullable;
053
054/**
055 * A test utility that verifies that your methods and constructors throw {@link
056 * NullPointerException} or {@link UnsupportedOperationException} whenever null is passed to a
057 * parameter whose declaration or type isn't annotated with an annotation with the simple name
058 * {@code Nullable}, {@code CheckForNull}, {@code NullableType}, or {@code NullableDecl}.
059 *
060 * <p>The tested methods and constructors are invoked -- each time with one parameter being null and
061 * the rest not null -- and the test fails if no expected exception is thrown. {@code
062 * NullPointerTester} uses best effort to pick non-null default values for many common JDK and Guava
063 * types, and also for interfaces and public classes that have public parameter-less constructors.
064 * When the non-null default value for a particular parameter type cannot be provided by {@code
065 * NullPointerTester}, the caller can provide a custom non-null default value for the parameter type
066 * via {@link #setDefault}.
067 *
068 * @author Kevin Bourrillion
069 * @since 10.0
070 */
071@GwtIncompatible
072@J2ktIncompatible
073@ElementTypesAreNonnullByDefault
074public final class NullPointerTester {
075
076  private final ClassToInstanceMap<Object> defaults = MutableClassToInstanceMap.create();
077  private final List<Member> ignoredMembers = Lists.newArrayList();
078
079  private ExceptionTypePolicy policy = ExceptionTypePolicy.NPE_OR_UOE;
080
081  public NullPointerTester() {
082    try {
083      /*
084       * Converter.apply has a non-nullable parameter type but doesn't throw for null arguments. For
085       * more information, see the comments in that class.
086       *
087       * We already know that that's how it behaves, and subclasses of Converter can't change that
088       * behavior. So there's no sense in making all subclass authors exclude the method from any
089       * NullPointerTester tests that they have.
090       */
091      ignoredMembers.add(Converter.class.getMethod("apply", Object.class));
092    } catch (NoSuchMethodException shouldBeImpossible) {
093      // OK, fine: If it doesn't exist, then there's chance that we're going to be asked to test it.
094    }
095  }
096
097  /**
098   * Sets a default value that can be used for any parameter of type {@code type}. Returns this
099   * object.
100   */
101  @CanIgnoreReturnValue
102  public <T> NullPointerTester setDefault(Class<T> type, T value) {
103    defaults.putInstance(type, checkNotNull(value));
104    return this;
105  }
106
107  /**
108   * Ignore {@code method} in the tests that follow. Returns this object.
109   *
110   * @since 13.0
111   */
112  @CanIgnoreReturnValue
113  public NullPointerTester ignore(Method method) {
114    ignoredMembers.add(checkNotNull(method));
115    return this;
116  }
117
118  /**
119   * Ignore {@code constructor} in the tests that follow. Returns this object.
120   *
121   * @since 22.0
122   */
123  @CanIgnoreReturnValue
124  public NullPointerTester ignore(Constructor<?> constructor) {
125    ignoredMembers.add(checkNotNull(constructor));
126    return this;
127  }
128
129  /**
130   * Runs {@link #testConstructor} on every constructor in class {@code c} that has at least {@code
131   * minimalVisibility}.
132   */
133  public void testConstructors(Class<?> c, Visibility minimalVisibility) {
134    for (Constructor<?> constructor : c.getDeclaredConstructors()) {
135      if (minimalVisibility.isVisible(constructor) && !isIgnored(constructor)) {
136        testConstructor(constructor);
137      }
138    }
139  }
140
141  /** Runs {@link #testConstructor} on every public constructor in class {@code c}. */
142  public void testAllPublicConstructors(Class<?> c) {
143    testConstructors(c, Visibility.PUBLIC);
144  }
145
146  /**
147   * Runs {@link #testMethod} on every static method of class {@code c} that has at least {@code
148   * minimalVisibility}, including those "inherited" from superclasses of the same package.
149   */
150  public void testStaticMethods(Class<?> c, Visibility minimalVisibility) {
151    for (Method method : minimalVisibility.getStaticMethods(c)) {
152      if (!isIgnored(method)) {
153        testMethod(null, method);
154      }
155    }
156  }
157
158  /**
159   * Runs {@link #testMethod} on every public static method of class {@code c}, including those
160   * "inherited" from superclasses of the same package.
161   */
162  public void testAllPublicStaticMethods(Class<?> c) {
163    testStaticMethods(c, Visibility.PUBLIC);
164  }
165
166  /**
167   * Runs {@link #testMethod} on every instance method of the class of {@code instance} with at
168   * least {@code minimalVisibility}, including those inherited from superclasses of the same
169   * package.
170   */
171  public void testInstanceMethods(Object instance, Visibility minimalVisibility) {
172    for (Method method : getInstanceMethodsToTest(instance.getClass(), minimalVisibility)) {
173      testMethod(instance, method);
174    }
175  }
176
177  ImmutableList<Method> getInstanceMethodsToTest(Class<?> c, Visibility minimalVisibility) {
178    ImmutableList.Builder<Method> builder = ImmutableList.builder();
179    for (Method method : minimalVisibility.getInstanceMethods(c)) {
180      if (!isIgnored(method)) {
181        builder.add(method);
182      }
183    }
184    return builder.build();
185  }
186
187  /**
188   * Runs {@link #testMethod} on every public instance method of the class of {@code instance},
189   * including those inherited from superclasses of the same package.
190   */
191  public void testAllPublicInstanceMethods(Object instance) {
192    testInstanceMethods(instance, Visibility.PUBLIC);
193  }
194
195  /**
196   * Verifies that {@code method} produces a {@link NullPointerException} or {@link
197   * UnsupportedOperationException} whenever <i>any</i> of its non-nullable parameters are null.
198   *
199   * @param instance the instance to invoke {@code method} on, or null if {@code method} is static
200   */
201  public void testMethod(@Nullable Object instance, Method method) {
202    Class<?>[] types = method.getParameterTypes();
203    for (int nullIndex = 0; nullIndex < types.length; nullIndex++) {
204      testMethodParameter(instance, method, nullIndex);
205    }
206  }
207
208  /**
209   * Verifies that {@code ctor} produces a {@link NullPointerException} or {@link
210   * UnsupportedOperationException} whenever <i>any</i> of its non-nullable parameters are null.
211   */
212  public void testConstructor(Constructor<?> ctor) {
213    Class<?> declaringClass = ctor.getDeclaringClass();
214    checkArgument(
215        Modifier.isStatic(declaringClass.getModifiers())
216            || declaringClass.getEnclosingClass() == null,
217        "Cannot test constructor of non-static inner class: %s",
218        declaringClass.getName());
219    Class<?>[] types = ctor.getParameterTypes();
220    for (int nullIndex = 0; nullIndex < types.length; nullIndex++) {
221      testConstructorParameter(ctor, nullIndex);
222    }
223  }
224
225  /**
226   * Verifies that {@code method} produces a {@link NullPointerException} or {@link
227   * UnsupportedOperationException} when the parameter in position {@code paramIndex} is null. If
228   * this parameter is marked nullable, this method does nothing.
229   *
230   * @param instance the instance to invoke {@code method} on, or null if {@code method} is static
231   */
232  public void testMethodParameter(
233      @Nullable final Object instance, final Method method, int paramIndex) {
234    method.setAccessible(true);
235    testParameter(instance, invokable(instance, method), paramIndex, method.getDeclaringClass());
236  }
237
238  /**
239   * Verifies that {@code ctor} produces a {@link NullPointerException} or {@link
240   * UnsupportedOperationException} when the parameter in position {@code paramIndex} is null. If
241   * this parameter is marked nullable, this method does nothing.
242   */
243  public void testConstructorParameter(Constructor<?> ctor, int paramIndex) {
244    ctor.setAccessible(true);
245    testParameter(null, Invokable.from(ctor), paramIndex, ctor.getDeclaringClass());
246  }
247
248  /** Visibility of any method or constructor. */
249  public enum Visibility {
250    PACKAGE {
251      @Override
252      boolean isVisible(int modifiers) {
253        return !Modifier.isPrivate(modifiers);
254      }
255    },
256
257    PROTECTED {
258      @Override
259      boolean isVisible(int modifiers) {
260        return Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers);
261      }
262    },
263
264    PUBLIC {
265      @Override
266      boolean isVisible(int modifiers) {
267        return Modifier.isPublic(modifiers);
268      }
269    };
270
271    abstract boolean isVisible(int modifiers);
272
273    /** Returns {@code true} if {@code member} is visible under {@code this} visibility. */
274    final boolean isVisible(Member member) {
275      return isVisible(member.getModifiers());
276    }
277
278    final Iterable<Method> getStaticMethods(Class<?> cls) {
279      ImmutableList.Builder<Method> builder = ImmutableList.builder();
280      for (Method method : getVisibleMethods(cls)) {
281        if (Invokable.from(method).isStatic()) {
282          builder.add(method);
283        }
284      }
285      return builder.build();
286    }
287
288    final Iterable<Method> getInstanceMethods(Class<?> cls) {
289      ConcurrentMap<Signature, Method> map = Maps.newConcurrentMap();
290      for (Method method : getVisibleMethods(cls)) {
291        if (!Invokable.from(method).isStatic()) {
292          map.putIfAbsent(new Signature(method), method);
293        }
294      }
295      return map.values();
296    }
297
298    private ImmutableList<Method> getVisibleMethods(Class<?> cls) {
299      // Don't use cls.getPackage() because it does nasty things like reading
300      // a file.
301      String visiblePackage = Reflection.getPackageName(cls);
302      ImmutableList.Builder<Method> builder = ImmutableList.builder();
303      for (Class<?> type : TypeToken.of(cls).getTypes().rawTypes()) {
304        if (!Reflection.getPackageName(type).equals(visiblePackage)) {
305          break;
306        }
307        for (Method method : type.getDeclaredMethods()) {
308          if (!method.isSynthetic() && isVisible(method)) {
309            builder.add(method);
310          }
311        }
312      }
313      return builder.build();
314    }
315  }
316
317  private static final class Signature {
318    private final String name;
319    private final ImmutableList<Class<?>> parameterTypes;
320
321    Signature(Method method) {
322      this(method.getName(), ImmutableList.copyOf(method.getParameterTypes()));
323    }
324
325    Signature(String name, ImmutableList<Class<?>> parameterTypes) {
326      this.name = name;
327      this.parameterTypes = parameterTypes;
328    }
329
330    @Override
331    public boolean equals(@Nullable Object obj) {
332      if (obj instanceof Signature) {
333        Signature that = (Signature) obj;
334        return name.equals(that.name) && parameterTypes.equals(that.parameterTypes);
335      }
336      return false;
337    }
338
339    @Override
340    public int hashCode() {
341      return Objects.hashCode(name, parameterTypes);
342    }
343  }
344
345  /**
346   * Verifies that {@code invokable} produces a {@link NullPointerException} or {@link
347   * UnsupportedOperationException} when the parameter in position {@code paramIndex} is null. If
348   * this parameter is marked nullable, this method does nothing.
349   *
350   * @param instance the instance to invoke {@code invokable} on, or null if {@code invokable} is
351   *     static
352   */
353  private void testParameter(
354      @Nullable Object instance, Invokable<?, ?> invokable, int paramIndex, Class<?> testedClass) {
355    /*
356     * com.google.common is starting to rely on type-use annotations, which aren't visible under
357     * Android VMs. So we skip testing there.
358     */
359    if (isAndroid() && Reflection.getPackageName(testedClass).startsWith("com.google.common")) {
360      return;
361    }
362    if (isPrimitiveOrNullable(invokable.getParameters().get(paramIndex))) {
363      return; // there's nothing to test
364    }
365    @Nullable Object[] params = buildParamList(invokable, paramIndex);
366    try {
367      @SuppressWarnings("unchecked") // We'll get a runtime exception if the type is wrong.
368      Invokable<Object, ?> unsafe = (Invokable<Object, ?>) invokable;
369      unsafe.invoke(instance, params);
370      Assert.fail(
371          "No exception thrown for parameter at index "
372              + paramIndex
373              + " from "
374              + invokable
375              + Arrays.toString(params)
376              + " for "
377              + testedClass);
378    } catch (InvocationTargetException e) {
379      Throwable cause = e.getCause();
380      if (policy.isExpectedType(cause)) {
381        return;
382      }
383      AssertionFailedError error =
384          new AssertionFailedError(
385              String.format(
386                  "wrong exception thrown from %s when passing null to %s parameter at index %s.%n"
387                      + "Full parameters: %s%n"
388                      + "Actual exception message: %s",
389                  invokable,
390                  invokable.getParameters().get(paramIndex).getType(),
391                  paramIndex,
392                  Arrays.toString(params),
393                  cause));
394      error.initCause(cause);
395      throw error;
396    } catch (IllegalAccessException e) {
397      throw new RuntimeException(e);
398    }
399  }
400
401  private @Nullable Object[] buildParamList(
402      Invokable<?, ?> invokable, int indexOfParamToSetToNull) {
403    ImmutableList<Parameter> params = invokable.getParameters();
404    @Nullable Object[] args = new Object[params.size()];
405
406    for (int i = 0; i < args.length; i++) {
407      Parameter param = params.get(i);
408      if (i != indexOfParamToSetToNull) {
409        args[i] = getDefaultValue(param.getType());
410        Assert.assertTrue(
411            "Can't find or create a sample instance for type '"
412                + param.getType()
413                + "'; please provide one using NullPointerTester.setDefault()",
414            args[i] != null || isNullable(param));
415      }
416    }
417    return args;
418  }
419
420  private <T> @Nullable T getDefaultValue(TypeToken<T> type) {
421    // We assume that all defaults are generics-safe, even if they aren't,
422    // we take the risk.
423    @SuppressWarnings("unchecked")
424    T defaultValue = (T) defaults.getInstance(type.getRawType());
425    if (defaultValue != null) {
426      return defaultValue;
427    }
428    @SuppressWarnings("unchecked") // All arbitrary instances are generics-safe
429    T arbitrary = (T) ArbitraryInstances.get(type.getRawType());
430    if (arbitrary != null) {
431      return arbitrary;
432    }
433    if (type.getRawType() == Class.class) {
434      // If parameter is Class<? extends Foo>, we return Foo.class
435      @SuppressWarnings("unchecked")
436      T defaultClass = (T) getFirstTypeParameter(type.getType()).getRawType();
437      return defaultClass;
438    }
439    if (type.getRawType() == TypeToken.class) {
440      // If parameter is TypeToken<? extends Foo>, we return TypeToken<Foo>.
441      @SuppressWarnings("unchecked")
442      T defaultType = (T) getFirstTypeParameter(type.getType());
443      return defaultType;
444    }
445    if (type.getRawType() == Converter.class) {
446      TypeToken<?> convertFromType = type.resolveType(Converter.class.getTypeParameters()[0]);
447      TypeToken<?> convertToType = type.resolveType(Converter.class.getTypeParameters()[1]);
448      @SuppressWarnings("unchecked") // returns default for both F and T
449      T defaultConverter = (T) defaultConverter(convertFromType, convertToType);
450      return defaultConverter;
451    }
452    if (type.getRawType().isInterface()) {
453      return newDefaultReturningProxy(type);
454    }
455    return null;
456  }
457
458  private <F, T> Converter<F, T> defaultConverter(
459      final TypeToken<F> convertFromType, final TypeToken<T> convertToType) {
460    return new Converter<F, T>() {
461      @Override
462      protected T doForward(F a) {
463        return doConvert(convertToType);
464      }
465
466      @Override
467      protected F doBackward(T b) {
468        return doConvert(convertFromType);
469      }
470
471      private /*static*/ <S> S doConvert(TypeToken<S> type) {
472        return checkNotNull(getDefaultValue(type));
473      }
474    };
475  }
476
477  private static TypeToken<?> getFirstTypeParameter(Type type) {
478    if (type instanceof ParameterizedType) {
479      return TypeToken.of(((ParameterizedType) type).getActualTypeArguments()[0]);
480    } else {
481      return TypeToken.of(Object.class);
482    }
483  }
484
485  private <T> T newDefaultReturningProxy(final TypeToken<T> type) {
486    return new DummyProxy() {
487      @Override
488      <R> @Nullable R dummyReturnValue(TypeToken<R> returnType) {
489        return getDefaultValue(returnType);
490      }
491    }.newProxy(type);
492  }
493
494  private static Invokable<?, ?> invokable(@Nullable Object instance, Method method) {
495    if (instance == null) {
496      return Invokable.from(method);
497    } else {
498      return TypeToken.of(instance.getClass()).method(method);
499    }
500  }
501
502  static boolean isPrimitiveOrNullable(Parameter param) {
503    return param.getType().getRawType().isPrimitive() || isNullable(param);
504  }
505
506  private static final ImmutableSet<String> NULLABLE_ANNOTATION_SIMPLE_NAMES =
507      ImmutableSet.of("CheckForNull", "Nullable", "NullableDecl", "NullableType");
508
509  static boolean isNullable(Invokable<?, ?> invokable) {
510    return NULLNESS_ANNOTATION_READER.isNullable(invokable);
511  }
512
513  static boolean isNullable(Parameter param) {
514    return NULLNESS_ANNOTATION_READER.isNullable(param);
515  }
516
517  private static boolean containsNullable(Annotation[] annotations) {
518    for (Annotation annotation : annotations) {
519      if (NULLABLE_ANNOTATION_SIMPLE_NAMES.contains(annotation.annotationType().getSimpleName())) {
520        return true;
521      }
522    }
523    return false;
524  }
525
526  private boolean isIgnored(Member member) {
527    return member.isSynthetic() || ignoredMembers.contains(member) || isEquals(member);
528  }
529
530  /**
531   * Returns true if the given member is a method that overrides {@link Object#equals(Object)}.
532   *
533   * <p>The documentation for {@link Object#equals} says it should accept null, so don't require an
534   * explicit {@code @Nullable} annotation (see <a
535   * href="https://github.com/google/guava/issues/1819">#1819</a>).
536   *
537   * <p>It is not necessary to consider visibility, return type, or type parameter declarations. The
538   * declaration of a method with the same name and formal parameters as {@link Object#equals} that
539   * is not public and boolean-returning, or that declares any type parameters, would be rejected at
540   * compile-time.
541   */
542  private static boolean isEquals(Member member) {
543    if (!(member instanceof Method)) {
544      return false;
545    }
546    Method method = (Method) member;
547    if (!method.getName().contentEquals("equals")) {
548      return false;
549    }
550    Class<?>[] parameters = method.getParameterTypes();
551    if (parameters.length != 1) {
552      return false;
553    }
554    if (!parameters[0].equals(Object.class)) {
555      return false;
556    }
557    return true;
558  }
559
560  /** Strategy for exception type matching used by {@link NullPointerTester}. */
561  private enum ExceptionTypePolicy {
562
563    /**
564     * Exceptions should be {@link NullPointerException} or {@link UnsupportedOperationException}.
565     */
566    NPE_OR_UOE() {
567      @Override
568      public boolean isExpectedType(Throwable cause) {
569        return cause instanceof NullPointerException
570            || cause instanceof UnsupportedOperationException;
571      }
572    },
573
574    /**
575     * Exceptions should be {@link NullPointerException}, {@link IllegalArgumentException}, or
576     * {@link UnsupportedOperationException}.
577     */
578    NPE_IAE_OR_UOE() {
579      @Override
580      public boolean isExpectedType(Throwable cause) {
581        return cause instanceof NullPointerException
582            || cause instanceof IllegalArgumentException
583            || cause instanceof UnsupportedOperationException;
584      }
585    };
586
587    public abstract boolean isExpectedType(Throwable cause);
588  }
589
590  private static boolean annotatedTypeExists() {
591    try {
592      Class.forName("java.lang.reflect.AnnotatedType");
593    } catch (ClassNotFoundException e) {
594      return false;
595    }
596    return true;
597  }
598
599  private static final NullnessAnnotationReader NULLNESS_ANNOTATION_READER =
600      annotatedTypeExists()
601          ? NullnessAnnotationReader.FROM_DECLARATION_AND_TYPE_USE_ANNOTATIONS
602          : NullnessAnnotationReader.FROM_DECLARATION_ANNOTATIONS_ONLY;
603
604  /**
605   * Looks for declaration nullness annotations and, if supported, type-use nullness annotations.
606   *
607   * <p>Under Android VMs, the methods for retrieving type-use annotations don't exist. This means
608   * that {@link NullPointerException} may misbehave under Android when used on classes that rely on
609   * type-use annotations.
610   *
611   * <p>Under j2objc, the necessary APIs exist, but some (perhaps all) return stub values, like
612   * empty arrays. Presumably {@link NullPointerException} could likewise misbehave under j2objc,
613   * but I don't know that anyone uses it there, anyway.
614   */
615  private enum NullnessAnnotationReader {
616    // Usages (which are unsafe only for Android) are guarded by the annotatedTypeExists() check.
617    @SuppressWarnings({"Java7ApiChecker", "AndroidApiChecker", "DoNotCall", "deprecation"})
618    FROM_DECLARATION_AND_TYPE_USE_ANNOTATIONS {
619      @Override
620      @IgnoreJRERequirement
621      boolean isNullable(Invokable<?, ?> invokable) {
622        return FROM_DECLARATION_ANNOTATIONS_ONLY.isNullable(invokable)
623            || containsNullable(invokable.getAnnotatedReturnType().getAnnotations());
624        // TODO(cpovirk): Should we also check isNullableTypeVariable?
625      }
626
627      @Override
628      @IgnoreJRERequirement
629      boolean isNullable(Parameter param) {
630        return FROM_DECLARATION_ANNOTATIONS_ONLY.isNullable(param)
631            || containsNullable(param.getAnnotatedType().getAnnotations())
632            || isNullableTypeVariable(param.getAnnotatedType().getType());
633      }
634
635      @IgnoreJRERequirement
636      boolean isNullableTypeVariable(Type type) {
637        if (!(type instanceof TypeVariable)) {
638          return false;
639        }
640        TypeVariable<?> typeVar = (TypeVariable<?>) type;
641        for (AnnotatedType bound : typeVar.getAnnotatedBounds()) {
642          // Until Java 15, the isNullableTypeVariable case here won't help:
643          // https://bugs.openjdk.java.net/browse/JDK-8202469
644          if (containsNullable(bound.getAnnotations()) || isNullableTypeVariable(bound.getType())) {
645            return true;
646          }
647        }
648        return false;
649      }
650    },
651    FROM_DECLARATION_ANNOTATIONS_ONLY {
652      @Override
653      boolean isNullable(Invokable<?, ?> invokable) {
654        return containsNullable(invokable.getAnnotations());
655      }
656
657      @Override
658      boolean isNullable(Parameter param) {
659        return containsNullable(param.getAnnotations());
660      }
661    };
662
663    abstract boolean isNullable(Invokable<?, ?> invokable);
664
665    abstract boolean isNullable(Parameter param);
666  }
667
668  private static boolean isAndroid() {
669    // Arguably it would make more sense to test "can we see type-use annotations" directly....
670    return checkNotNull(System.getProperty("java.runtime.name", "")).contains("Android");
671  }
672}