ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/CompletableFuture.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/CompletableFuture.java (file contents):
Revision 1.17 by dl, Sun Dec 30 14:45:59 2012 UTC vs.
Revision 1.18 by dl, Sun Dec 30 16:11:36 2012 UTC

# Line 1935 | Line 1935 | public class CompletableFuture<T> implem
1935                  if (ex != null || c == null) {
1936                      if (ex == null)
1937                          ex = new NullPointerException();
1938 <                    dst.completeExceptionally(new RuntimeException(ex));
1939 <                    return;
1938 >                    else
1939 >                        ex = new RuntimeException(ex);
1940                  }
1941 <                ThenCopy<U> d = null;
1942 <                Object s;
1943 <                if ((s = c.result) == null) {
1944 <                    CompletionNode p = new CompletionNode
1945 <                        (d = new ThenCopy<U>(c, dst));
1946 <                    while ((s = c.result) == null) {
1947 <                        if (UNSAFE.compareAndSwapObject
1948 <                            (c, COMPLETIONS, p.next = c.completions, p))
1949 <                            break;
1941 >                else {
1942 >                    ThenCopy<U> d = null;
1943 >                    Object s;
1944 >                    if ((s = c.result) == null) {
1945 >                        CompletionNode p = new CompletionNode
1946 >                            (d = new ThenCopy<U>(c, dst));
1947 >                        while ((s = c.result) == null) {
1948 >                            if (UNSAFE.compareAndSwapObject
1949 >                                (c, COMPLETIONS, p.next = c.completions, p))
1950 >                                break;
1951 >                        }
1952                      }
1953 <                    if ((s = c.result) == null || !d.compareAndSet(0, 1))
1954 <                        return;
1955 <                }
1956 <                U u;
1957 <                if (s instanceof AltResult) {
1958 <                    if ((ex = ((AltResult)s).ex) != null)
1959 <                        dst.completeExceptionally(new RuntimeException(ex));
1960 <                    u = null;
1961 <                }
1962 <                else
1961 <                    u = (U) s;
1962 <                if (ex == null) {
1963 <                    try {
1964 <                        dst.complete(u);
1965 <                    } catch (Throwable rex) {
1966 <                        dst.completeExceptionally(rex);
1953 >                    if (s != null && (d == null || d.compareAndSet(0, 1))) {
1954 >                        U u;
1955 >                        if (s instanceof AltResult) {
1956 >                            ex = ((AltResult)s).ex;  // no rewrap
1957 >                            u = null;
1958 >                        }
1959 >                        else
1960 >                            u = (U) s;
1961 >                        if (ex == null)
1962 >                            dst.complete(u);
1963                      }
1964                  }
1965 <                c.postComplete();
1965 >                if (ex != null)
1966 >                    dst.completeExceptionally(ex);
1967 >                if (c != null && c.result != null)
1968 >                    c.postComplete();
1969              }
1970          }
1971      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines