Search in sources :

Example 11 with Nullable

use of org.checkerframework.checker.nullness.qual.Nullable in project checker-framework by typetools.

the class DelayQueue method peek.

/**
 * Retrieves, but does not remove, the head of this queue, or
 * returns {@code null} if this queue is empty.  Unlike
 * {@code poll}, if no expired elements are available in the queue,
 * this method returns the element that will expire next,
 * if one exists.
 *
 * @return the head of this queue, or {@code null} if this
 *         queue is empty
 */
@Nullable
public E peek() {
    final ReentrantLock lock = this.lock;
    lock.lock();
    try {
        return q.peek();
    } finally {
        lock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 12 with Nullable

use of org.checkerframework.checker.nullness.qual.Nullable in project checker-framework by typetools.

the class DelayQueue method poll.

/**
 * Retrieves and removes the head of this queue, waiting if necessary
 * until an element with an expired delay is available on this queue,
 * or the specified wait time expires.
 *
 * @return the head of this queue, or {@code null} if the
 *         specified waiting time elapses before an element with
 *         an expired delay becomes available
 * @throws InterruptedException {@inheritDoc}
 */
@Nullable
public E poll(long timeout, TimeUnit unit) throws InterruptedException {
    long nanos = unit.toNanos(timeout);
    final ReentrantLock lock = this.lock;
    lock.lockInterruptibly();
    try {
        for (; ; ) {
            E first = q.peek();
            if (first == null) {
                if (nanos <= 0)
                    return null;
                else
                    nanos = available.awaitNanos(nanos);
            } else {
                long delay = first.getDelay(NANOSECONDS);
                if (delay <= 0)
                    return q.poll();
                if (nanos <= 0)
                    return null;
                // don't retain ref while waiting
                first = null;
                if (nanos < delay || leader != null)
                    nanos = available.awaitNanos(nanos);
                else {
                    Thread thisThread = Thread.currentThread();
                    leader = thisThread;
                    try {
                        long timeLeft = available.awaitNanos(delay);
                        nanos -= delay - timeLeft;
                    } finally {
                        if (leader == thisThread)
                            leader = null;
                    }
                }
            }
        }
    } finally {
        if (leader == null && q.peek() != null)
            available.signal();
        lock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 13 with Nullable

use of org.checkerframework.checker.nullness.qual.Nullable in project checker-framework by typetools.

the class JarFile method getManifestFromReference.

@Nullable
private Manifest getManifestFromReference() throws IOException {
    Manifest man = manRef != null ? manRef.get() : null;
    if (man == null) {
        JarEntry manEntry = getManEntry();
        // If found then load the manifest
        if (manEntry != null) {
            if (verify) {
                byte[] b = getBytes(manEntry);
                man = new Manifest(new ByteArrayInputStream(b));
                if (!jvInitialized) {
                    jv = new JarVerifier(b);
                }
            } else {
                man = new Manifest(super.getInputStream(manEntry));
            }
            manRef = new SoftReference(man);
        }
    }
    return man;
}
Also used : SoftReference(java.lang.ref.SoftReference) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 14 with Nullable

use of org.checkerframework.checker.nullness.qual.Nullable in project checker-framework by typetools.

the class ZipFile method getInputStream.

/**
 * Returns an input stream for reading the contents of the specified
 * zip file entry.
 *
 * <p> Closing this ZIP file will, in turn, close all input
 * streams that have been returned by invocations of this method.
 *
 * @param entry the zip file entry
 * @return the input stream for reading the contents of the specified
 * zip file entry.
 * @throws ZipException if a ZIP format error has occurred
 * @throws IOException if an I/O error has occurred
 * @throws IllegalStateException if the zip file has been closed
 */
@Nullable
public InputStream getInputStream(ZipEntry entry) throws IOException {
    if (entry == null) {
        throw new NullPointerException("entry");
    }
    long jzentry = 0;
    ZipFileInputStream in = null;
    synchronized (this) {
        ensureOpen();
        if (!zc.isUTF8() && (entry.flag & EFS) != 0) {
            jzentry = getEntry(jzfile, zc.getBytesUTF8(entry.name), false);
        } else {
            jzentry = getEntry(jzfile, zc.getBytes(entry.name), false);
        }
        if (jzentry == 0) {
            return null;
        }
        in = new ZipFileInputStream(jzentry);
        switch(getEntryMethod(jzentry)) {
            case STORED:
                synchronized (streams) {
                    streams.put(in, null);
                }
                return in;
            case DEFLATED:
                // MORE: Compute good size for inflater stream:
                // Inflater likes a bit of slack
                long size = getEntrySize(jzentry) + 2;
                if (size > 65536)
                    size = 8192;
                if (size <= 0)
                    size = 4096;
                Inflater inf = getInflater();
                InputStream is = new ZipFileInflaterInputStream(in, inf, (int) size);
                synchronized (streams) {
                    streams.put(is, inf);
                }
                return is;
            default:
                throw new ZipException("invalid compression method");
        }
    }
}
Also used : InputStream(java.io.InputStream) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 15 with Nullable

use of org.checkerframework.checker.nullness.qual.Nullable in project checker-framework by typetools.

the class PropertyDescriptor method getReadMethod.

/**
 * Gets the method that should be used to read the property value.
 *
 * @return The method that should be used to read the property value.
 * May return null if the property can't be read.
 */
@Pure
@Nullable
public synchronized Method getReadMethod() {
    Method readMethod = this.readMethodRef.get();
    if (readMethod == null) {
        Class<?> cls = getClass0();
        if (cls == null || (readMethodName == null && !this.readMethodRef.isSet())) {
            // The read method was explicitly set to null.
            return null;
        }
        String nextMethodName = Introspector.GET_PREFIX + getBaseName();
        if (readMethodName == null) {
            Class<?> type = getPropertyType0();
            if (type == boolean.class || type == null) {
                readMethodName = Introspector.IS_PREFIX + getBaseName();
            } else {
                readMethodName = nextMethodName;
            }
        }
        // Since there can be multiple write methods but only one getter
        // method, find the getter method first so that you know what the
        // property type is.  For booleans, there can be "is" and "get"
        // methods.  If an "is" method exists, this is the official
        // reader method so look for this one first.
        readMethod = Introspector.findMethod(cls, readMethodName, 0);
        if ((readMethod == null) && !readMethodName.equals(nextMethodName)) {
            readMethodName = nextMethodName;
            readMethod = Introspector.findMethod(cls, readMethodName, 0);
        }
        try {
            setReadMethod(readMethod);
        } catch (IntrospectionException ex) {
        // fall
        }
    }
    return readMethod;
}
Also used : Method(java.lang.reflect.Method) Pure(org.checkerframework.dataflow.qual.Pure) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Aggregations

Nullable (org.checkerframework.checker.nullness.qual.Nullable)27 TypeElement (javax.lang.model.element.TypeElement)7 VariableElement (javax.lang.model.element.VariableElement)4 TreePath (com.sun.source.util.TreePath)3 Method (java.lang.reflect.Method)3 ReentrantLock (java.util.concurrent.locks.ReentrantLock)3 Element (javax.lang.model.element.Element)3 ClassTree (com.sun.source.tree.ClassTree)2 MethodTree (com.sun.source.tree.MethodTree)2 VariableTree (com.sun.source.tree.VariableTree)2 ExecutableElement (javax.lang.model.element.ExecutableElement)2 PackageElement (javax.lang.model.element.PackageElement)2 Prefix (org.checkerframework.checker.units.qual.Prefix)2 AssignmentNode (org.checkerframework.dataflow.cfg.node.AssignmentNode)2 Node (org.checkerframework.dataflow.cfg.node.Node)2 Pure (org.checkerframework.dataflow.qual.Pure)2 AnnotationBuilder (org.checkerframework.javacutil.AnnotationBuilder)2 AnnotationTree (com.sun.source.tree.AnnotationTree)1 AssignmentTree (com.sun.source.tree.AssignmentTree)1 BlockTree (com.sun.source.tree.BlockTree)1