org.checkerframework.checker.nullness.compatqual.NullableDecl Java Examples

The following examples show how to use org.checkerframework.checker.nullness.compatqual.NullableDecl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BindingAdapters.java    From lttrs-android with Apache License 2.0 6 votes vote down vote up
@BindingAdapter("identities")
public static void setIdentities(final AppCompatSpinner spinner, final List<IdentityWithNameAndEmail> identities) {
    final List<String> representations;
    if (identities == null) {
        representations = Collections.emptyList();
    } else {
        representations = Lists.transform(identities, new Function<IdentityWithNameAndEmail, String>() {
            @NullableDecl
            @Override
            public String apply(IdentityWithNameAndEmail input) {
                return EmailAddressUtil.toString(input.getEmailAddress());
            }
        });
    }
    final ArrayAdapter<String> adapter = new ArrayAdapter<>(
            spinner.getContext(),
            android.R.layout.simple_spinner_item,
            representations);
    adapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
}
 
Example #2
Source File: ModelServerClassification.java    From hazelcast-jet-demos with Apache License 2.0 6 votes vote down vote up
/**
 * Adapt a {@link ListenableFuture} to java standard {@link
 * CompletableFuture}, which is used by Jet.
 */
private static <T> CompletableFuture<T> toCompletableFuture(ListenableFuture<T> lf) {
    CompletableFuture<T> f = new CompletableFuture<>();
    // note that we don't handle CompletableFuture.cancel()
    Futures.addCallback(lf, new FutureCallback<T>() {
        @Override
        public void onSuccess(@NullableDecl T result) {
            f.complete(result);
        }

        @Override
        public void onFailure(Throwable t) {
            f.completeExceptionally(t);
        }
    }, directExecutor());
    return f;
}
 
Example #3
Source File: FormatOptions.java    From flogger with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(@NullableDecl Object o) {
  // Various functions ensure that the same instance gets re-used, so it seems likely that it's
  // worth optimizing for it here.
  if (o == this) {
    return true;
  }
  if (o instanceof FormatOptions) {
    FormatOptions other = (FormatOptions) o;
    return (other.flags == flags) && (other.width == width) && (other.precision == precision);
  }
  return false;
}
 
Example #4
Source File: MainRepository.java    From lttrs-android with Apache License 2.0 5 votes vote down vote up
public ListenableFuture<Void> insertAccountsRefreshMailboxes(final String username,
                                                             final String password,
                                                             final HttpUrl sessionResource,
                                                             final String primaryAccountId,
                                                             final Map<String, Account> accounts) {
    final SettableFuture<Void> settableFuture = SettableFuture.create();
    IO_EXECUTOR.execute(() -> {
        try {
            List<AccountWithCredentials> credentials = appDatabase.accountDao().insert(
                    username,
                    password,
                    sessionResource,
                    primaryAccountId,
                    accounts
            );
            SetupCache.invalidate();
            final Collection<ListenableFuture<Status>> mailboxRefreshes = Collections2.transform(
                    credentials,
                    new Function<AccountWithCredentials, ListenableFuture<Status>>() {
                        @NullableDecl
                        @Override
                        public ListenableFuture<Status> apply(@NullableDecl AccountWithCredentials account) {
                            return retrieveMailboxes(account);
                        }
                    });
            settableFuture.setFuture(Futures.whenAllComplete(mailboxRefreshes).call(() -> null, MoreExecutors.directExecutor()));
        } catch (Exception e) {
            settableFuture.setException(e);
        }
    });
    return settableFuture;
}
 
Example #5
Source File: WorkInfoUtil.java    From lttrs-android with Apache License 2.0 5 votes vote down vote up
private static Collection<WorkInfo.State> transform(List<WorkInfo> info) {
    return Collections2.transform(info, new Function<WorkInfo, WorkInfo.State>() {
        @NullableDecl
        @Override
        public WorkInfo.State apply(@NullableDecl WorkInfo input) {
            return input == null ? null : input.getState();
        }
    });
}
 
Example #6
Source File: LogDataFormatterTest.java    From flogger with Apache License 2.0 5 votes vote down vote up
private static SimpleLogHandler getSimpleLogHandler() {
  return new SimpleLogHandler() {
    private String captured = null;

    @Override
    public void handleFormattedLogMessage(Level lvl, String msg, @NullableDecl Throwable e) {
      captured = msg;
    }

    @Override
    public String toString() {
      return captured;
    }
  };
}
 
Example #7
Source File: SetupViewModel.java    From lttrs-android with Apache License 2.0 5 votes vote down vote up
private void processAccounts(final Session session) {
    final Map<String, Account> accounts = session.getAccounts(MailAccountCapability.class);
    LOGGER.info("found {} accounts with mail capability", accounts.size());
    if (accounts.size() == 1) {
        final ListenableFuture<Void> insertFuture = mainRepository.insertAccountsRefreshMailboxes(
                Strings.nullToEmpty(emailAddress.getValue()),
                Strings.nullToEmpty(password.getValue()),
                getHttpSessionResource(),
                session.getPrimaryAccount(MailAccountCapability.class),
                accounts
        );
        Futures.addCallback(insertFuture, new FutureCallback<Void>() {
            @Override
            public void onSuccess(@NullableDecl Void result) {
                redirection.postValue(new Event<>(Target.LTTRS));
            }

            @Override
            public void onFailure(@NonNull Throwable cause) {
                loading.postValue(false);
                warningMessage.postValue(new Event<>(
                        getApplication().getString(R.string.could_not_store_account_credentials)
                ));

            }
        }, MoreExecutors.directExecutor());
    } else {
        loading.postValue(false);
        redirection.postValue(new Event<>(Target.SELECT_ACCOUNTS));
        //store accounts in view model
    }
}
 
Example #8
Source File: LogContext.java    From flogger with Apache License 2.0 5 votes vote down vote up
@Override
public final void logVarargs(String message, @NullableDecl Object[] params) {
  if (shouldLog()) {
    // Copy the varargs array (because we didn't create it and this is quite a rare case).
    logImpl(message, Arrays.copyOf(params, params.length));
  }
}
 
Example #9
Source File: LogContext.java    From flogger with Apache License 2.0 5 votes vote down vote up
@Override
public final void log(
    String message,
    @NullableDecl Object p1,
    @NullableDecl Object p2,
    @NullableDecl Object p3,
    @NullableDecl Object p4) {
  if (shouldLog()) logImpl(message, p1, p2, p3, p4);
}
 
Example #10
Source File: LogContext.java    From flogger with Apache License 2.0 5 votes vote down vote up
@Override
public final void log(
    String msg,
    @NullableDecl Object p1,
    @NullableDecl Object p2,
    @NullableDecl Object p3,
    @NullableDecl Object p4,
    @NullableDecl Object p5,
    @NullableDecl Object p6,
    @NullableDecl Object p7) {
  if (shouldLog()) logImpl(msg, p1, p2, p3, p4, p5, p6, p7);
}
 
Example #11
Source File: LogContext.java    From flogger with Apache License 2.0 5 votes vote down vote up
@Override
public final void log(
    String msg,
    @NullableDecl Object p1,
    @NullableDecl Object p2,
    @NullableDecl Object p3,
    @NullableDecl Object p4,
    @NullableDecl Object p5,
    @NullableDecl Object p6) {
  if (shouldLog()) logImpl(msg, p1, p2, p3, p4, p5, p6);
}
 
Example #12
Source File: LogContext.java    From flogger with Apache License 2.0 5 votes vote down vote up
@Override
public final void log(
    String msg,
    @NullableDecl Object p1,
    @NullableDecl Object p2,
    @NullableDecl Object p3,
    @NullableDecl Object p4,
    @NullableDecl Object p5,
    @NullableDecl Object p6,
    @NullableDecl Object p7,
    @NullableDecl Object p8,
    @NullableDecl Object p9,
    @NullableDecl Object p10) {
  if (shouldLog()) logImpl(msg, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
}
 
Example #13
Source File: LogContext.java    From flogger with Apache License 2.0 5 votes vote down vote up
@Override
public final <T> API with(MetadataKey<T> key, @NullableDecl T value) {
  // Null keys are always bad (even if the value is also null). This is one of the few places
  // where the logger API will throw a runtime exception (and as such it's important to ensure
  // the NoOp implementation also does the check). The reasoning for this is that the metadata
  // key is never expected to be passed user data, and should always be a static constant.
  // Because of this it's always going to be an obvious code error if we get a null here.
  checkNotNull(key, "metadata key");
  if (value != null) {
    addMetadata(key, value);
  }
  return api();
}
 
Example #14
Source File: LoggingApi.java    From flogger with Apache License 2.0 5 votes vote down vote up
/** Logs a message with formatted arguments (see {@link #log(String, Object)} for details). */
void log(
    String msg,
    @NullableDecl Object p1,
    @NullableDecl Object p2,
    @NullableDecl Object p3,
    @NullableDecl Object p4);
 
Example #15
Source File: LoggingApi.java    From flogger with Apache License 2.0 5 votes vote down vote up
/** Logs a message with formatted arguments (see {@link #log(String, Object)} for details). */
void log(
    String msg,
    @NullableDecl Object p1,
    @NullableDecl Object p2,
    @NullableDecl Object p3,
    @NullableDecl Object p4,
    @NullableDecl Object p5);
 
Example #16
Source File: LoggingApi.java    From flogger with Apache License 2.0 5 votes vote down vote up
/** Logs a message with formatted arguments (see {@link #log(String, Object)} for details). */
void log(
    String msg,
    @NullableDecl Object p1,
    @NullableDecl Object p2,
    @NullableDecl Object p3,
    @NullableDecl Object p4,
    @NullableDecl Object p5,
    @NullableDecl Object p6);
 
Example #17
Source File: LoggingApi.java    From flogger with Apache License 2.0 5 votes vote down vote up
/** Logs a message with formatted arguments (see {@link #log(String, Object)} for details). */
void log(
    String msg,
    @NullableDecl Object p1,
    @NullableDecl Object p2,
    @NullableDecl Object p3,
    @NullableDecl Object p4,
    @NullableDecl Object p5,
    @NullableDecl Object p6,
    @NullableDecl Object p7,
    @NullableDecl Object p8);
 
Example #18
Source File: LoggingApi.java    From flogger with Apache License 2.0 5 votes vote down vote up
/** Logs a message with formatted arguments (see {@link #log(String, Object)} for details). */
void log(
    String msg,
    @NullableDecl Object p1,
    @NullableDecl Object p2,
    @NullableDecl Object p3,
    @NullableDecl Object p4,
    @NullableDecl Object p5,
    @NullableDecl Object p6,
    @NullableDecl Object p7,
    @NullableDecl Object p8,
    @NullableDecl Object p9,
    @NullableDecl Object p10);
 
Example #19
Source File: LoggingApi.java    From flogger with Apache License 2.0 5 votes vote down vote up
/** Logs a message with formatted arguments (see {@link #log(String, Object)} for details). */
void log(
    String msg,
    @NullableDecl Object p1,
    @NullableDecl Object p2,
    @NullableDecl Object p3,
    @NullableDecl Object p4,
    @NullableDecl Object p5,
    @NullableDecl Object p6,
    @NullableDecl Object p7,
    @NullableDecl Object p8,
    @NullableDecl Object p9,
    @NullableDecl Object p10,
    Object... rest);
 
Example #20
Source File: LoggingApi.java    From flogger with Apache License 2.0 5 votes vote down vote up
@Override
public final void log(
    String msg,
    @NullableDecl Object p1,
    @NullableDecl Object p2,
    @NullableDecl Object p3,
    @NullableDecl Object p4,
    @NullableDecl Object p5,
    @NullableDecl Object p6,
    @NullableDecl Object p7,
    @NullableDecl Object p8,
    @NullableDecl Object p9,
    @NullableDecl Object p10,
    Object... rest) {}
 
Example #21
Source File: LogContext.java    From flogger with Apache License 2.0 5 votes vote down vote up
@Override
public final void log(
    String msg,
    @NullableDecl Object p1,
    @NullableDecl Object p2,
    @NullableDecl Object p3,
    @NullableDecl Object p4,
    @NullableDecl Object p5) {
  if (shouldLog()) logImpl(msg, p1, p2, p3, p4, p5);
}
 
Example #22
Source File: LoggingApi.java    From flogger with Apache License 2.0 5 votes vote down vote up
@Override
public final void log(
    String msg,
    @NullableDecl Object p1,
    @NullableDecl Object p2,
    @NullableDecl Object p3,
    @NullableDecl Object p4,
    @NullableDecl Object p5,
    @NullableDecl Object p6,
    @NullableDecl Object p7,
    @NullableDecl Object p8,
    @NullableDecl Object p9) {}
 
Example #23
Source File: LogContext.java    From flogger with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public final API withInjectedLogSite(
    String internalClassName,
    String methodName,
    int encodedLineNumber,
    @NullableDecl String sourceFileName) {
  return withInjectedLogSite(
      LogSite.injectedLogSite(internalClassName, methodName, encodedLineNumber, sourceFileName));
}
 
Example #24
Source File: LoggingApi.java    From flogger with Apache License 2.0 5 votes vote down vote up
@Override
public final void log(
    String msg,
    @NullableDecl Object p1,
    @NullableDecl Object p2,
    @NullableDecl Object p3,
    @NullableDecl Object p4,
    @NullableDecl Object p5,
    @NullableDecl Object p6,
    @NullableDecl Object p7) {}
 
Example #25
Source File: LoggingApi.java    From flogger with Apache License 2.0 5 votes vote down vote up
@Override
public final void log(
    String msg,
    @NullableDecl Object p1,
    @NullableDecl Object p2,
    @NullableDecl Object p3,
    @NullableDecl Object p4,
    @NullableDecl Object p5,
    @NullableDecl Object p6) {}
 
Example #26
Source File: LoggingApi.java    From flogger with Apache License 2.0 5 votes vote down vote up
@Override
public final void log(
    String msg,
    @NullableDecl Object p1,
    @NullableDecl Object p2,
    @NullableDecl Object p3,
    @NullableDecl Object p4,
    @NullableDecl Object p5) {}
 
Example #27
Source File: ABIProviderTest.java    From eosio-java with MIT License 5 votes vote down vote up
@Test
public void testGetAbiAsync() {
    final CountDownLatch testLock = new CountDownLatch(1);
    final String[] retrievedEosioAbiJsonStrings = {new String()};

    ListeningExecutorService service = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10));
    ListenableFuture<String> getEosioAbiFuture = service.submit(new Callable<String>() {
        @Override
        public String call() throws Exception {
            // Its not thread safe to use the global mocks like this but we're not trying to
            // run concurrent calls.
            IABIProvider abiProvider = new ABIProviderImpl(mockRpcProvider, mockSerializationProvider);
            return abiProvider.getAbi(chainId, new EOSIOName("eosio"));
        }
    });
    Futures.addCallback(getEosioAbiFuture, new FutureCallback<String>() {
        @Override
        public void onSuccess(@NullableDecl String result) {
            retrievedEosioAbiJsonStrings[0] = result;
            testLock.countDown();
        }

        @Override
        public void onFailure(Throwable t) {
            testLock.countDown();
        }
    }, MoreExecutors.directExecutor());

    try {
        testLock.await(2000, TimeUnit.MILLISECONDS);
        assertNotNull(retrievedEosioAbiJsonStrings[0]);
        assertFalse(retrievedEosioAbiJsonStrings[0].isEmpty());
        assertEquals(eosioAbiJsonString, retrievedEosioAbiJsonStrings[0]);
    } catch (InterruptedException interruptedException) {
        fail("Interrupted waiting for getAbi() to complete: " +
                interruptedException.getLocalizedMessage());
    }
}
 
Example #28
Source File: LogContext.java    From flogger with Apache License 2.0 5 votes vote down vote up
@Override
public final void log(
    String msg,
    @NullableDecl Object p1,
    @NullableDecl Object p2,
    @NullableDecl Object p3,
    @NullableDecl Object p4,
    @NullableDecl Object p5,
    @NullableDecl Object p6,
    @NullableDecl Object p7,
    @NullableDecl Object p8,
    @NullableDecl Object p9,
    @NullableDecl Object p10,
    Object... rest) {
  if (shouldLog()) {
    // Manually create a new varargs array and copy the parameters in.
    Object[] params = new Object[rest.length + 10];
    params[0] = p1;
    params[1] = p2;
    params[2] = p3;
    params[3] = p4;
    params[4] = p5;
    params[5] = p6;
    params[6] = p7;
    params[7] = p8;
    params[8] = p9;
    params[9] = p10;
    System.arraycopy(rest, 0, params, 10, rest.length);
    logImpl(msg, params);
  }
}
 
Example #29
Source File: StaticMethodCaller.java    From flogger with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the value of the specified static no-argument method, or null if the method cannot be
 * called or the returned value is of the wrong type.
 *
 * @param propertyName the name of a system property which is expected to hold a value like
 *     {@code "com.foo.Bar#someMethod"}, where the referenced method is a public, no-argument
 *     getter for an instance of the given type.
 * @param type the expected type (or supertype) of the returned value (generified types are not
 *     supported).
 */
@NullableDecl
public static <T> T callGetterFromSystemProperty(String propertyName, Class<T> type) {
  String getter = readProperty(propertyName);
  if (getter == null) {
    return null;
  }
  int idx = getter.indexOf('#');
  if (idx <= 0 || idx == getter.length() - 1) {
    error("invalid getter (expected <class>#<method>): %s\n", getter);
    return null;
  }
  return callStaticMethod(getter.substring(0, idx), getter.substring(idx + 1), type);
}
 
Example #30
Source File: Metadata.java    From flogger with Apache License 2.0 4 votes vote down vote up
@Override
@NullableDecl
public <T> T findValue(MetadataKey<T> key) {
  return null;
}