org.checkerframework.checker.nullness.qual.EnsuresNonNull Java Examples

The following examples show how to use org.checkerframework.checker.nullness.qual.EnsuresNonNull. 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: WebvttCssStyle.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@EnsuresNonNull({"targetId", "targetTag", "targetClasses", "targetVoice"})
public void reset() {
  targetId = "";
  targetTag = "";
  targetClasses = Collections.emptyList();
  targetVoice = "";
  fontFamily = null;
  hasFontColor = false;
  hasBackgroundColor = false;
  linethrough = UNSPECIFIED;
  underline = UNSPECIFIED;
  bold = UNSPECIFIED;
  italic = UNSPECIFIED;
  fontSizeUnit = UNSPECIFIED;
  textAlign = null;
}
 
Example #2
Source File: LazyPlatformMBeanServer.java    From glowroot with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #3
Source File: CentralModule.java    From glowroot with Apache License 2.0 6 votes vote down vote up
@EnsuresNonNull("startupLogger")
@SuppressWarnings("contracts.postcondition.not.satisfied")
private static void initLogging(File confDir, File logDir) {
    File logbackXmlOverride = new File(confDir, "logback.xml");
    if (logbackXmlOverride.exists()) {
        System.setProperty("logback.configurationFile", logbackXmlOverride.getAbsolutePath());
    }
    String prior = System.getProperty("glowroot.log.dir");
    System.setProperty("glowroot.log.dir", logDir.getPath());
    try {
        startupLogger = LoggerFactory.getLogger("org.glowroot");
    } finally {
        System.clearProperty("logback.configurationFile");
        if (prior == null) {
            System.clearProperty("glowroot.log.dir");
        } else {
            System.setProperty("glowroot.log.dir", prior);
        }
    }
    // install jul-to-slf4j bridge for guava/grpc/protobuf which log to jul
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();
}
 
Example #4
Source File: Transaction.java    From glowroot with Apache License 2.0 6 votes vote down vote up
@GuardedBy("mainThreadContext")
@EnsuresNonNull({"alreadyMergedAuxThreadTimers", "alreadyMergedAuxThreadStats",
        "alreadyMergedAuxQueries", "alreadyMergedAuxServiceCalls"})
private void initAlreadyMergedAuxComponentsIfNeeded() {
    if (alreadyMergedAuxThreadTimers == null) {
        alreadyMergedAuxThreadTimers = new RootTimerCollectorImpl();
    }
    if (alreadyMergedAuxThreadStats == null) {
        alreadyMergedAuxThreadStats = new ThreadStatsCollectorImpl();
    }
    if (alreadyMergedAuxQueries == null) {
        alreadyMergedAuxQueries = new QueryCollector(maxQueryAggregates,
                AdvancedConfig.OVERALL_AGGREGATE_QUERIES_HARD_LIMIT_MULTIPLIER);
    }
    if (alreadyMergedAuxServiceCalls == null) {
        alreadyMergedAuxServiceCalls = new ServiceCallCollector(maxServiceCallAggregates,
                AdvancedConfig.OVERALL_AGGREGATE_QUERIES_HARD_LIMIT_MULTIPLIER);
    }
}
 
Example #5
Source File: State.java    From zetasketch with Apache License 2.0 6 votes vote down vote up
/** Resets all fields to their default value. */
// Using UnknownInitialization as this method is called both from the constructor (when it would
// be UnderInitialization(State.class)) as well as by users manually when wishing to reset the
// state (when it is Initialized(State.class)).
// https://checkerframework.org/manual/#initialization-checker
@EnsuresNonNull({"type", "valueType"})
public void clear(@UnknownInitialization State this) {
  type = DEFAULT_TYPE;
  numValues = DEFAULT_NUM_VALUES;
  encodingVersion = DEFAULT_ENCODING_VERSION;
  valueType = DEFAULT_VALUE_TYPE;
  sparseSize = DEFAULT_SPARSE_SIZE;
  precision = DEFAULT_PRECISION_OR_NUM_BUCKETS;
  sparsePrecision = DEFAULT_SPARSE_PRECISION_OR_NUM_BUCKETS;
  data = null;
  sparseData = null;
}
 
Example #6
Source File: DecoderInputBuffer.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Ensures that {@link #data} is large enough to accommodate a write of a given length at its
 * current position.
 *
 * <p>If the capacity of {@link #data} is sufficient this method does nothing. If the capacity is
 * insufficient then an attempt is made to replace {@link #data} with a new {@link ByteBuffer}
 * whose capacity is sufficient. Data up to the current position is copied to the new buffer.
 *
 * @param length The length of the write that must be accommodated, in bytes.
 * @throws IllegalStateException If there is insufficient capacity to accommodate the write and
 *     the buffer replacement mode of the holder is {@link #BUFFER_REPLACEMENT_MODE_DISABLED}.
 */
@EnsuresNonNull("data")
public void ensureSpaceForWrite(int length) {
  if (data == null) {
    data = createReplacementByteBuffer(length);
    return;
  }
  // Check whether the current buffer is sufficient.
  int capacity = data.capacity();
  int position = data.position();
  int requiredCapacity = position + length;
  if (capacity >= requiredCapacity) {
    return;
  }
  // Instantiate a new buffer if possible.
  ByteBuffer newData = createReplacementByteBuffer(requiredCapacity);
  // Copy data up to the current position from the old buffer to the new one.
  if (position > 0) {
    data.flip();
    newData.put(data);
  }
  // Set the new buffer.
  data = newData;
}
 
Example #7
Source File: HlsSampleStreamWrapper.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@RequiresNonNull("trackGroups")
@EnsuresNonNull("trackGroupToSampleQueueIndex")
private void mapSampleQueuesToMatchTrackGroups() {
  int trackGroupCount = trackGroups.length;
  trackGroupToSampleQueueIndex = new int[trackGroupCount];
  Arrays.fill(trackGroupToSampleQueueIndex, C.INDEX_UNSET);
  for (int i = 0; i < trackGroupCount; i++) {
    for (int queueIndex = 0; queueIndex < sampleQueues.length; queueIndex++) {
      SampleQueue sampleQueue = sampleQueues[queueIndex];
      if (formatsMatch(sampleQueue.getUpstreamFormat(), trackGroups.get(i).getFormat(0))) {
        trackGroupToSampleQueueIndex[i] = queueIndex;
        break;
      }
    }
  }
  for (HlsSampleStream sampleStream : hlsSampleStreams) {
    sampleStream.bindSampleQueue();
  }
}
 
Example #8
Source File: Assertions.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #9
Source File: NotGuava.java    From glowroot with Apache License 2.0 5 votes vote down vote up
@EnsuresNonNull("#1")
static <T extends /*@Nullable*/ Object> /*@NonNull*/ T checkNotNull(T reference) {
    if (reference == null) {
        throw new NullPointerException();
    }
    return reference;
}
 
Example #10
Source File: FlacExtractor.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@RequiresNonNull({"decoderJni", "extractorOutput", "trackOutput"}) // Requires initialized.
@EnsuresNonNull({"streamMetadata", "outputFrameHolder"}) // Ensures stream metadata decoded.
@SuppressWarnings({"contracts.postcondition.not.satisfied"})
private void decodeStreamMetadata(ExtractorInput input) throws InterruptedException, IOException {
  if (streamMetadataDecoded) {
    return;
  }

  FlacStreamMetadata streamMetadata;
  try {
    streamMetadata = decoderJni.decodeStreamMetadata();
  } catch (IOException e) {
    decoderJni.reset(/* newPosition= */ 0);
    input.setRetryPosition(/* position= */ 0, e);
    throw e;
  }

  streamMetadataDecoded = true;
  if (this.streamMetadata == null) {
    this.streamMetadata = streamMetadata;
    binarySearchSeeker =
        outputSeekMap(decoderJni, streamMetadata, input.getLength(), extractorOutput);
    Metadata metadata = id3MetadataDisabled ? null : id3Metadata;
    if (streamMetadata.metadata != null) {
      metadata = streamMetadata.metadata.copyWithAppendedEntriesFrom(metadata);
    }
    outputFormat(streamMetadata, metadata, trackOutput);
    outputBuffer.reset(streamMetadata.maxDecodedFrameSize());
    outputFrameHolder = new OutputFrameHolder(ByteBuffer.wrap(outputBuffer.data));
  }
}
 
Example #11
Source File: LazyHistogram.java    From glowroot with Apache License 2.0 5 votes vote down vote up
@EnsuresNonNull("histogram")
private void convertValuesToHistogram() {
    // tracking nanoseconds, but only at microsecond precision (to save histogram space)
    histogram = new Histogram(1000, 2000, HISTOGRAM_SIGNIFICANT_DIGITS);
    histogram.setAutoResize(true);
    for (int i = 0; i < size; i++) {
        histogram.recordValue(values[i]);
    }
    values = new long[0];
}
 
Example #12
Source File: Assertions.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #13
Source File: Assertions.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #14
Source File: Assertions.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #15
Source File: Assertions.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #16
Source File: Assertions.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #17
Source File: DownloadHelper.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@EnsuresNonNull({
  "trackGroupArrays",
  "mappedTrackInfos",
  "trackSelectionsByPeriodAndRenderer",
  "immutableTrackSelectionsByPeriodAndRenderer",
  "mediaPreparer",
  "mediaPreparer.timeline",
  "mediaPreparer.mediaPeriods"
})
@SuppressWarnings("nullness:contracts.postcondition.not.satisfied")
private void assertPreparedWithMedia() {
  Assertions.checkState(isPreparedWithMedia);
}
 
Example #18
Source File: Assertions.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #19
Source File: FlacExtractor.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@EnsuresNonNull({"decoderJni", "extractorOutput", "trackOutput"}) // Ensures initialized.
@SuppressWarnings({"contracts.postcondition.not.satisfied"})
private FlacDecoderJni initDecoderJni(ExtractorInput input) {
  FlacDecoderJni decoderJni = Assertions.checkNotNull(this.decoderJni);
  decoderJni.setData(input);
  return decoderJni;
}
 
Example #20
Source File: NormalRepresentation.java    From zetasketch with Apache License 2.0 5 votes vote down vote up
/** Initializes the state's data if it is not already. */
@EnsuresNonNull("#1.data")
private static void ensureData(State state) {
  if (!state.hasData()) {
    state.data = ByteSlice.allocate(1 << state.precision);
  }
}
 
Example #21
Source File: FlacExtractor.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@EnsuresNonNull({"decoderJni", "extractorOutput", "trackOutput"}) // Ensures initialized.
@SuppressWarnings({"contracts.postcondition.not.satisfied"})
private FlacDecoderJni initDecoderJni(ExtractorInput input) {
  FlacDecoderJni decoderJni = Assertions.checkNotNull(this.decoderJni);
  decoderJni.setData(input);
  return decoderJni;
}
 
Example #22
Source File: FlacExtractor.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@RequiresNonNull({"decoderJni", "extractorOutput", "trackOutput"}) // Requires initialized.
@EnsuresNonNull({"streamMetadata", "outputFrameHolder"}) // Ensures stream metadata decoded.
@SuppressWarnings({"contracts.postcondition.not.satisfied"})
private void decodeStreamMetadata(ExtractorInput input) throws InterruptedException, IOException {
  if (streamMetadataDecoded) {
    return;
  }

  FlacStreamMetadata streamMetadata;
  try {
    streamMetadata = decoderJni.decodeStreamMetadata();
  } catch (IOException e) {
    decoderJni.reset(/* newPosition= */ 0);
    input.setRetryPosition(/* position= */ 0, e);
    throw e;
  }

  streamMetadataDecoded = true;
  if (this.streamMetadata == null) {
    this.streamMetadata = streamMetadata;
    binarySearchSeeker =
        outputSeekMap(decoderJni, streamMetadata, input.getLength(), extractorOutput);
    Metadata metadata = id3MetadataDisabled ? null : id3Metadata;
    if (streamMetadata.metadata != null) {
      metadata = streamMetadata.metadata.copyWithAppendedEntriesFrom(metadata);
    }
    outputFormat(streamMetadata, metadata, trackOutput);
    outputBuffer.reset(streamMetadata.maxDecodedFrameSize());
    outputFrameHolder = new OutputFrameHolder(ByteBuffer.wrap(outputBuffer.data));
  }
}
 
Example #23
Source File: DownloadHelper.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@EnsuresNonNull({
  "trackGroupArrays",
  "mappedTrackInfos",
  "trackSelectionsByPeriodAndRenderer",
  "immutableTrackSelectionsByPeriodAndRenderer",
  "mediaPreparer",
  "mediaPreparer.timeline",
  "mediaPreparer.mediaPeriods"
})
@SuppressWarnings("nullness:contracts.postcondition.not.satisfied")
private void assertPreparedWithMedia() {
  Assertions.checkState(isPreparedWithMedia);
}
 
Example #24
Source File: DecoderInputBuffer.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Clears {@link #supplementalData} and ensures that it's large enough to accommodate {@code
 * length} bytes.
 *
 * @param length The length of the supplemental data that must be accommodated, in bytes.
 */
@EnsuresNonNull("supplementalData")
public void resetSupplementalData(int length) {
  if (supplementalData == null || supplementalData.capacity() < length) {
    supplementalData = ByteBuffer.allocate(length);
  } else {
    supplementalData.clear();
  }
}
 
Example #25
Source File: DownloadHelper.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@EnsuresNonNull({
  "trackGroupArrays",
  "mappedTrackInfos",
  "trackSelectionsByPeriodAndRenderer",
  "immutableTrackSelectionsByPeriodAndRenderer",
  "mediaPreparer",
  "mediaPreparer.timeline",
  "mediaPreparer.mediaPeriods"
})
@SuppressWarnings("nullness:contracts.postcondition.not.satisfied")
private void assertPreparedWithMedia() {
  Assertions.checkState(isPreparedWithMedia);
}
 
Example #26
Source File: Assertions.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #27
Source File: Assertions.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #28
Source File: Assertions.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #29
Source File: Assertions.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Throws {@link IllegalStateException} 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 IllegalStateException If {@code reference} is null.
 */
@SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"})
@EnsuresNonNull({"#1"})
public static <T> T checkStateNotNull(@Nullable T reference) {
  if (ExoPlayerLibraryInfo.ASSERTIONS_ENABLED && reference == null) {
    throw new IllegalStateException();
  }
  return reference;
}
 
Example #30
Source File: Util.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
/** 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;
}