/** * Casts a nullable variable to a non-null variable without runtime null check. * * <p>Use {@link Assertions#checkNotNull(Object)} to throw if the value is null. */ @SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"}) @EnsuresNonNull("#1") public static <T> T castNonNull(@Nullable T value) { return value; }
/** * Throws {@link NullPointerException} if {@code reference} is null. * * @param <T> The type of the reference. * @param reference The reference. * @return The non-null reference that was validated. * @throws NullPointerException If {@code reference} is null. */ @SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"}) @EnsuresNonNull({"#1"}) public static <T> T checkNotNull(@Nullable T reference) { if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && reference == null) { throw new NullPointerException(); } return reference; }
@EnsuresNonNull("#1") <T extends /*@Nullable*/ Object>
/** * Throws {@link IllegalArgumentException} if {@code string} is null or zero length. * * @param string The string to check. * @return The non-null, non-empty string that was validated. * @throws IllegalArgumentException If {@code string} is null or 0-length. */ @SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"}) @EnsuresNonNull({"#1"}) public static String checkNotEmpty(@Nullable String string) { if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && TextUtils.isEmpty(string)) { throw new IllegalArgumentException(); } return string; }
/** * Throws {@link NullPointerException} if {@code reference} is null. * * @param <T> The type of the reference. * @param reference The reference. * @param errorMessage The exception message to use if the check fails. The message is converted * to a string using {@link String#valueOf(Object)}. * @return The non-null reference that was validated. * @throws NullPointerException If {@code reference} is null. */ @SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"}) @EnsuresNonNull({"#1"}) public static <T> T checkNotNull(@Nullable T reference, Object errorMessage) { if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && reference == null) { throw new NullPointerException(String.valueOf(errorMessage)); } return reference; }
/** * Throws {@link IllegalArgumentException} if {@code string} is null or zero length. * * @param string The string to check. * @param errorMessage The exception message to use if the check fails. The message is converted * to a string using {@link String#valueOf(Object)}. * @return The non-null, non-empty string that was validated. * @throws IllegalArgumentException If {@code string} is null or 0-length. */ @SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"}) @EnsuresNonNull({"#1"}) public static String checkNotEmpty(@Nullable String string, Object errorMessage) { if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && TextUtils.isEmpty(string)) { throw new IllegalArgumentException(String.valueOf(errorMessage)); } return string; }
/** Casts a nullable type array to a non-null type array without runtime null check. */ @SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"}) @EnsuresNonNull("#1") public static <T> T[] castNonNullTypeArray(@NullableType T[] value) { return value; }
/** * Like castNonNull, but whereas that method only checks and casts the * reference itself, this traverses all levels of the argument array. * The array is recursively checked to ensure that all elements at * every array level are non-null. * @see #castNonNull(Object) */ public static @EnsuresNonNull("#1") <T extends /*@Nullable*/ Object> /*@NonNull*/ T /*@NonNull*/ [][][] castNonNullDeep(T /*@Nullable*/ [] /*@Nullable*/ [] /*@Nullable*/ [] arr) { return (/*@NonNull*/ T[][][]) castNonNullArray(arr); }
/** * Like castNonNull, but whereas that method only checks and casts the * reference itself, this traverses all levels of the argument array. * The array is recursively checked to ensure that all elements at * every array level are non-null. * @see #castNonNull(Object) */ public static @EnsuresNonNull("#1") <T extends /*@Nullable*/ Object> /*@NonNull*/ T /*@NonNull*/ [][][][][] castNonNullDeep(T /*@Nullable*/ [] /*@Nullable*/ [] /*@Nullable*/ [] /*@Nullable*/ [] /*@Nullable*/ [] arr) { return (/*@NonNull*/ T[][][][][]) castNonNullArray(arr); }
/** * Like castNonNull, but whereas that method only checks and casts the * reference itself, this traverses all levels of the argument array. * The array is recursively checked to ensure that all elements at * every array level are non-null. * @see #castNonNull(Object) */ public static @EnsuresNonNull("#1") <T extends /*@Nullable*/ Object> /*@NonNull*/ T /*@NonNull*/ [] castNonNullDeep(T /*@Nullable*/ [] arr) { return (/*@NonNull*/ T[]) castNonNullArray(arr); }
/** * Like castNonNull, but whereas that method only checks and casts the * reference itself, this traverses all levels of the argument array. * The array is recursively checked to ensure that all elements at * every array level are non-null. * @see #castNonNull(Object) */ public static @EnsuresNonNull("#1") <T extends /*@Nullable*/ Object> /*@NonNull*/ T /*@NonNull*/ [][] castNonNullDeep(T /*@Nullable*/ [] /*@Nullable*/ [] arr) { return (/*@NonNull*/ T[][]) castNonNullArray(arr); }
/** * Like castNonNull, but whereas that method only checks and casts the * reference itself, this traverses all levels of the argument array. * The array is recursively checked to ensure that all elements at * every array level are non-null. * @see #castNonNull(Object) */ public static @EnsuresNonNull("#1") <T extends /*@Nullable*/ Object> /*@NonNull*/ T /*@NonNull*/ [][][][] castNonNullDeep(T /*@Nullable*/ [] /*@Nullable*/ [] /*@Nullable*/ [] /*@Nullable*/ [] arr) { return (/*@NonNull*/ T[][][][]) castNonNullArray(arr); }
@EnsuresNonNull("provider") private FileSessionCredentialsProvider getUnderlyingProvider() { FileSessionCredentialsProvider syncedProvider = provider; if (syncedProvider == null) { synchronized (config) { syncedProvider = provider; if (syncedProvider == null) { syncedProvider = new FileSessionCredentialsProvider(config.getFileSessionCredentials()); provider = syncedProvider; } } } return syncedProvider; }
/** * This class can be used by multiple threads, so this function should be thread-safe to avoid extra * script compilation. */ @EnsuresNonNull("compiledScript") private JavaScriptAggregator.ScriptAggregator getCompiledScript() { // JavaScript configuration should be checked when it's actually used because someone might still want Druid // nodes to be able to deserialize JavaScript-based objects even though JavaScript is disabled. Preconditions.checkState(config.isEnabled(), "JavaScript is disabled"); JavaScriptAggregator.ScriptAggregator syncedCompiledScript = compiledScript; if (syncedCompiledScript == null) { synchronized (config) { syncedCompiledScript = compiledScript; if (syncedCompiledScript == null) { syncedCompiledScript = compileScript(fnAggregate, fnReset, fnCombine); compiledScript = syncedCompiledScript; } } } return syncedCompiledScript; }
/** * {@link #compute} can be called by multiple threads, so this function should be thread-safe to avoid extra * script compilation. */ @EnsuresNonNull("fn") private Function getCompiledScript() { // JavaScript configuration should be checked when it's actually used because someone might still want Druid // nodes to be able to deserialize JavaScript-based objects even though JavaScript is disabled. Preconditions.checkState(config.isEnabled(), "JavaScript is disabled"); Function syncedFn = fn; if (syncedFn == null) { synchronized (config) { syncedFn = fn; if (syncedFn == null) { syncedFn = compile(function); fn = syncedFn; } } } return syncedFn; }
/** * {@link #apply(Object)} can be called by multiple threads, so this function should be thread-safe to avoid extra * script compilation. */ @EnsuresNonNull("fn") private Function<Object, String> getCompiledScript() { // JavaScript configuration should be checked when it's actually used because someone might still want Druid // nodes to be able to deserialize JavaScript-based objects even though JavaScript is disabled. Preconditions.checkState(config.isEnabled(), "JavaScript is disabled"); Function<Object, String> syncedFn = fn; if (syncedFn == null) { synchronized (config) { syncedFn = fn; if (syncedFn == null) { syncedFn = compile(function); fn = syncedFn; } } } return syncedFn; }
/** * This class can be used by multiple threads, so this function should be thread-safe to avoid extra * script compilation. */ @EnsuresNonNull("predicateFactory") private JavaScriptPredicateFactory getPredicateFactory() { // JavaScript configuration should be checked when it's actually used because someone might still want Druid // nodes to be able to deserialize JavaScript-based objects even though JavaScript is disabled. Preconditions.checkState(config.isEnabled(), "JavaScript is disabled"); JavaScriptPredicateFactory syncedFnPredicateFactory = predicateFactory; if (syncedFnPredicateFactory == null) { synchronized (config) { syncedFnPredicateFactory = predicateFactory; if (syncedFnPredicateFactory == null) { syncedFnPredicateFactory = new JavaScriptPredicateFactory(function, extractionFn); predicateFactory = syncedFnPredicateFactory; } } } return syncedFnPredicateFactory; }
@EnsuresNonNull("#1") static <T extends /*@Nullable*/ Object> /*@NonNull*/ T checkNotNull(T reference) { if (reference == null) { throw new NullPointerException(); } return reference; } }
@EnsuresNonNull("platformMBeanServer") private void ensureInit() throws Exception { if (platformMBeanServer != null) { return; } // don't hold initListeners lock while waiting for platform mbean server to be created // as this blocks lazyRegisterMBean if (waitForContainerToCreatePlatformMBeanServer) { waitForContainerToCreatePlatformMBeanServer(); } synchronized (initListeners) { if (platformMBeanServer != null) { return; } platformMBeanServer = init(); } }
@EnsuresNonNull("startupLogger") public static void initLogging(List<File> confDirs, File logDir, @Nullable Instrumentation instrumentation) {