Tue, 29 Mar 2016 10:48:49 +0000
8143647: Javac compiles method reference that allows results in an IllegalAccessError
Summary: Lambda implementation method synthesized by javac should not mention inaccessible types.
Reviewed-by: mcimadamore
1 /*
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 /*
26 * @test
27 * @bug 8068399
28 * @summary structural most specific and stuckness
29 */
31 import java.util.function.Function;
32 import java.util.stream.IntStream;
33 import java.util.stream.Stream;
35 public class T8068399 {
37 public static class Spectrum {
38 public double[] getEnergy() {
39 return new double[0];
40 }
41 }
43 protected Spectrum spectrum;
45 public static class Ref<T> {
47 T value;
49 public Ref() {
50 }
52 public Ref(T value) {
53 this.value = value;
54 }
56 public boolean isNull() {
57 return value == null;
58 }
60 public T get() {
61 return value;
62 }
64 public void set(T value) {
65 this.value = value;
66 }
67 }
69 public static <T>T maxKey(Stream<T> stream, Function<T, Double> function) {
70 Ref<Double> max = new Ref<>();
71 Ref<T> index = new Ref<>();
72 stream.forEach(v -> {
73 Double value = function.apply(v);
75 if (max.isNull() || value > max.get()) {
76 max.set(value);
77 index.set(v);
78 }
79 });
81 return index.get();
82 }
84 public static int interpolate(int x, int x0, int x1, int y0, int y1) {
85 return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
86 }
88 public static double interpolate(double x, double x0, double x1, double y0, double y1) {
89 return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
90 }
92 protected int getXByFrequency(double frequency) {
93 return (int) Math.round(interpolate(frequency,
94 getMinSpectrumCoord(),
95 getMaxSpectrumCoord(),
96 0, getWidth()));
97 }
99 private int getWidth() {
100 return 0;
101 }
103 private double getMaxSpectrumCoord() {
104 return 0;
105 }
107 private double getMinSpectrumCoord() {
108 return 0;
109 }
111 void foo() {
112 int maxBpmIndex = 0;
113 int xcur = getXByFrequency(maxKey(IntStream.range(0, maxBpmIndex).boxed(),
114 i -> Math.abs(spectrum.getEnergy()[i])));
115 }
117 public static void main(String [] args) {
118 }
119 }