test/langtools/tools/javac/scope/RemoveSymbolTest.java
author bobv
Tue, 07 Nov 2017 10:30:53 -0500
changeset 47801 c7b50c23ea71
parent 47216 71c04702a3d5
permissions -rw-r--r--
8190283: Default heap sizing options select a MaxHeapSize larger than available physical memory in some cases Reviewed-by: tschatzl, sjohanss
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30999
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
     1
/*
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
     4
 *
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
     8
 *
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    13
 * accompanied this code).
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    14
 *
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    18
 *
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    21
 * questions.
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    22
 */
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    23
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    24
/*
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    25
 * @test
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    26
 * @bug 8080842
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    27
 * @summary Ensure Scope impl can cope with remove() when a field and method share the name.
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    28
 * @run main RemoveSymbolTest
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    29
 */
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    30
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    31
import java.util.Iterator;
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    32
import java.util.LinkedList;
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    33
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    34
public class RemoveSymbolTest<W> implements Iterable<W> {
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    35
    static class Widget {
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    36
        private String name;
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    37
        Widget(String s) { name = s; }
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    38
        @Override public String toString() { return name; }
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    39
    }
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    40
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    41
    private LinkedList<W> data;
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    42
    // Instantiate an Iterable instance using a Lambda expression.
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    43
    // Causes ClassFormatError if a local variable of type Widget is named after one of the methods.
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    44
    private final Iterable<W> myIterator1 = () -> new Iterator<W>() {
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    45
        private W hasNext = null;
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    46
        private int index = 0;
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    47
        @Override public boolean hasNext() { return index < data.size(); }
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    48
        @Override public W next() { return data.get(index++); }
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    49
    };
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    50
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    51
    // Instantiate an Iterable instance using an anonymous class.
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    52
    // Always works fine regardless of the name of the local variable.
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    53
    private final Iterable<W> myIterator2 =
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    54
        new Iterable<W>() {
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    55
        @Override
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    56
        public Iterator<W> iterator() {
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    57
            return new Iterator<W>() {
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    58
                private W hasNext = null;
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    59
                private int index = 0;
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    60
                @Override public boolean hasNext() { return index < data.size(); }
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    61
                @Override public W next() { return data.get(index++); }
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    62
            };
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    63
        }
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    64
    };
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    65
    public RemoveSymbolTest() { data = new LinkedList<>(); }
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    66
    public void add(W e) { data.add(e); }
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    67
    @Override public String toString() { return data.toString(); }
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    68
    @Override public Iterator<W> iterator() { return myIterator1.iterator(); }
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    69
    public static void main(String[] args) {
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    70
        RemoveSymbolTest<Widget> widgets = new RemoveSymbolTest<>();
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    71
        widgets.add(new Widget("W1"));
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    72
        widgets.add(new Widget("W2"));
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    73
        widgets.add(new Widget("W3"));
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    74
        System.out.println(".foreach() call: ");
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    75
        widgets.forEach(w -> System.out.println(w + " "));
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    76
    }
f1bb0191a5a7 8080842: Using Lambda Expression with name clash results in ClassFormatError
sadayapalam
parents:
diff changeset
    77
}