title: ClassFormatError in java 8?
body: <p>I was making a class similar to <code>java.util.LinkedList</code>, and got a completely unexpected <code>ClassFormatError</code>. My IDE shows no warnings. FYI, I am using Java 8u20. <strong>Update: fixed in Java 8u60.</strong> </p>
  
  <p>T̶h̶i̶s̶ ̶i̶n̶c̶l̶u̶d̶e̶s̶ ̶a̶l̶l̶ ̶r̶e̶l̶e̶v̶a̶n̶t̶ ̶m̶e̶t̶h̶o̶d̶s̶:̶  Updated example as fully compilable:</p>
  
  <pre><code>import java.io.Serializable;
  import java.util.*;
  import java.util.function.Function;
  
  public class Foo&lt;E&gt; implements Deque&lt;E&gt;, Serializable {
      private static final long serialVersionUID = 0L;
  
      private final Node sentinel = sentinelInit();
      private final Iterable&lt;Node&gt; nodes = (Iterable&lt;Node&gt; &amp; Serializable) () -&gt; new Iterator&lt;Node&gt;() {
          @SuppressWarnings("UnusedDeclaration")
          private static final long serialVersionUID = 0L;
  
          private Node next = sentinel.next;
  
          @Override
          public boolean hasNext() {
              return next != sentinel;
          }
  
          @Override
          public Node next() {
              if (!hasNext()) {
                  throw new NoSuchElementException();
              }
              Node old = next;
              next = next.next;
              return old;
          }
  
          @Override
          public void remove() {
               if (next.previous == sentinel) {
                  throw new IllegalStateException();
              }
              removeNode(next.previous);
          }
      };
  
      @Override
      public boolean isEmpty() {
          return false;
      }
  
      @Override
      public Object[] toArray() {
          return new Object[0];
      }
  
      @Override
      public &lt;T&gt; T[] toArray(T[] a) {
          return null;
      }
  
      @Override
      public boolean containsAll(Collection&lt;?&gt; c) {
          return false;
      }
  
      @Override
      public boolean removeAll(Collection&lt;?&gt; c) {
          return false;
      }
  
      @Override
      public boolean retainAll(Collection&lt;?&gt; c) {
          return false;
      }
  
      @Override
      public void clear() {
  
      }
  
      @Override
      public void addFirst(E e) {
  
      }
  
      @Override
      public void addLast(E e) {
  
      }
  
      @Override
      public boolean offerLast(E e) {
          return false;
      }
  
      @Override
      public E removeFirst() {
          return null;
      }
  
      @Override
      public E removeLast() {
          return null;
      }
  
      @Override
      public E pollFirst() {
          return null;
      }
  
      @Override
      public E getFirst() {
          return null;
      }
  
      @Override
      public E getLast() {
          return null;
      }
  
      @Override
      public E peekFirst() {
          return null;
      }
  
      @Override
      public boolean removeFirstOccurrence(Object o) {
          return false;
      }
  
      @Override
      public boolean removeLastOccurrence(Object o) {
          return false;
      }
  
      @Override
      public E remove() {
          return null;
      }
  
      @Override
      public E element() {
         return null;
      }
  
      @Override
      public void push(E e) {
  
      }
  
      @Override
      public E pop() {
          return null;
      }
  
      @Override
      public boolean contains(Object o) {
          return false;
      }
  
      @Override
      public boolean offerFirst(E e) {
          return false;
      }
  
      @Override
      public E pollLast() {
          return null;
      }
  
      @Override
      public E peekLast() {
          return null;
      }
  
      @Override
      public boolean offer(E e) {
          Node node = new Node(e);
          sentinel.previous.next = node;
          node.previous = sentinel.previous;
          sentinel.previous = node;
          node.next = sentinel;
          return true;
      }
  
      @Override
      public E poll() {
          return null;
      }
  
      @Override
      public E peek() {
          return null;
      }
  
      @Override
      public boolean remove(Object o) {
          for (Node node : nodes) {
              if (node.value.equals(o)) {
                  removeNode(node);
                  return true;
              }
          }
          return false;
      }
  
      @Override
      public int size() {
          return 0;
      }
  
      @Override
      public Iterator&lt;E&gt; descendingIterator() {
          return null;
      }
  
      @Override
      public Iterator&lt;E&gt; iterator() {
          return new Iterator&lt;E&gt;() {
              private final Iterator&lt;Node&gt; backingIter = nodes.iterator();
  
              @Override
              public boolean hasNext() {
                  return backingIter.hasNext();
              }
  
              @Override
              public E next() {
                  return backingIter.next().value;
              }
  
              @Override
              public void remove() {
                  backingIter.remove();
              }
          };
      }
  
      private Node sentinelInit() {
          Node sentinel = new Node();
          sentinel.next = sentinel;
          sentinel.previous = sentinel;
          return sentinel;
      }
  
      private void removeNode(Node node) {
          node.previous.next = node.next;
          node.next.previous = node.previous;
      }
  
      private class Node implements Serializable {
          private static final long serialVersionUID = 0L;
          public E value;
          public Node next;
          public Node previous;
  
          public Node(E value) {
              this.value = value;
          }
  
          public Node() {
              this(null);
          }
      }
  
      public static &lt;I, O&gt; List&lt;O&gt; map(Function&lt;? super I, O&gt; function, Iterable&lt;I&gt; objects) {
          ArrayList&lt;O&gt; returned = new ArrayList&lt;&gt;();
          for (I obj : objects) {
              returned.add(function.apply(obj));
          }
          return returned;
      }
  
      @Override
      public boolean addAll(Collection&lt;? extends E&gt; c) {
          boolean ret = false;
          for (boolean changed : map(this::add, c)) {
              if (changed) {
                  ret = true;
              }
          }
          return ret;
      }
  
      @Override
      public boolean add(E e) {
          if (!offer(e)) {
              throw new IllegalStateException();
          }
          return true;
      }
  
      public static void main(String[] args) {
          Foo&lt;String&gt; list = new Foo&lt;&gt;();
          System.out.println("Constructed list");
          list.addAll(Arrays.asList("a", "B", "c"));
          System.out.println("Added a, B and c.");
          list.forEach(System.out::println);
          list.remove("B");
          list.forEach(System.out::println);
      }
  }
  </code></pre>
  
  <p>Here is the output:</p>
  
  <pre class="lang-none prettyprint-override"><code>Constructed list
  Added a, B and c.
  Exception in thread "main" java.lang.ClassFormatError: Duplicate field name&amp;signature in class file uk/org/me/Foo$1
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:455)
      at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:367)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      at uk.org.me.Foo.lambda$new$c83cc381$1(Foo.java:18)
      at uk.org.me.Foo$$Lambda$1/1392838282.iterator(Unknown Source)
      at uk.org.me.Foo$2.&lt;init&gt;(Foo.java:222)
      at uk.org.me.Foo.iterator(Foo.java:221)
      at java.lang.Iterable.forEach(Iterable.java:74)
      at uk.org.me.Foo.main(Foo.java:300)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:483)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
  </code></pre>