Thu, 05 Jan 2017 18:58:06 +0000
8168774: Polymorhic signature method check crashes javac
Summary: Check for polysig method assumes arity is greater than zero
Reviewed-by: vromero
mcimadamore@852 | 1 | /* |
jlahoda@2028 | 2 | * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. |
mcimadamore@852 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
mcimadamore@852 | 4 | * |
mcimadamore@852 | 5 | * This code is free software; you can redistribute it and/or modify it |
mcimadamore@852 | 6 | * under the terms of the GNU General Public License version 2 only, as |
mcimadamore@852 | 7 | * published by the Free Software Foundation. Oracle designates this |
mcimadamore@852 | 8 | * particular file as subject to the "Classpath" exception as provided |
mcimadamore@852 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
mcimadamore@852 | 10 | * |
mcimadamore@852 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
mcimadamore@852 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
mcimadamore@852 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
mcimadamore@852 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
mcimadamore@852 | 15 | * accompanied this code). |
mcimadamore@852 | 16 | * |
mcimadamore@852 | 17 | * You should have received a copy of the GNU General Public License version |
mcimadamore@852 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
mcimadamore@852 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
mcimadamore@852 | 20 | * |
mcimadamore@852 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
mcimadamore@852 | 22 | * or visit www.oracle.com if you need additional information or have any |
mcimadamore@852 | 23 | * questions. |
mcimadamore@852 | 24 | */ |
mcimadamore@852 | 25 | |
mcimadamore@852 | 26 | package com.sun.tools.javac.code; |
mcimadamore@852 | 27 | |
mcimadamore@852 | 28 | import java.util.HashMap; |
mcimadamore@852 | 29 | import java.util.Map; |
mcimadamore@852 | 30 | |
jlahoda@2028 | 31 | import com.sun.tools.javac.tree.EndPosTable; |
jlahoda@2028 | 32 | import com.sun.tools.javac.tree.JCTree; |
mcimadamore@852 | 33 | import com.sun.tools.javac.util.Assert; |
mcimadamore@852 | 34 | import com.sun.tools.javac.util.Context; |
jjg@1357 | 35 | import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
mcimadamore@852 | 36 | import com.sun.tools.javac.util.ListBuffer; |
mcimadamore@852 | 37 | |
mcimadamore@852 | 38 | /** |
mcimadamore@852 | 39 | * |
mcimadamore@852 | 40 | * <p><b>This is NOT part of any supported API. |
mcimadamore@852 | 41 | * If you write code that depends on this, you do so at your own risk. |
mcimadamore@852 | 42 | * This code and its internal interfaces are subject to change or |
mcimadamore@852 | 43 | * deletion without notice.</b> |
mcimadamore@852 | 44 | */ |
mcimadamore@852 | 45 | public class DeferredLintHandler { |
mcimadamore@852 | 46 | protected static final Context.Key<DeferredLintHandler> deferredLintHandlerKey = |
mcimadamore@852 | 47 | new Context.Key<DeferredLintHandler>(); |
mcimadamore@852 | 48 | |
mcimadamore@852 | 49 | public static DeferredLintHandler instance(Context context) { |
mcimadamore@852 | 50 | DeferredLintHandler instance = context.get(deferredLintHandlerKey); |
mcimadamore@852 | 51 | if (instance == null) |
mcimadamore@852 | 52 | instance = new DeferredLintHandler(context); |
mcimadamore@852 | 53 | return instance; |
mcimadamore@852 | 54 | } |
mcimadamore@852 | 55 | |
mcimadamore@852 | 56 | protected DeferredLintHandler(Context context) { |
mcimadamore@852 | 57 | context.put(deferredLintHandlerKey, this); |
jlahoda@2028 | 58 | this.currentPos = IMMEDIATE_POSITION; |
mcimadamore@852 | 59 | } |
mcimadamore@852 | 60 | |
jlahoda@2028 | 61 | /**An interface for deferred lint reporting - loggers passed to |
jlahoda@2028 | 62 | * {@link #report(LintLogger) } will be called when |
jlahoda@2028 | 63 | * {@link #flush(DiagnosticPosition) } is invoked. |
jlahoda@2028 | 64 | */ |
mcimadamore@852 | 65 | public interface LintLogger { |
mcimadamore@852 | 66 | void report(); |
mcimadamore@852 | 67 | } |
mcimadamore@852 | 68 | |
mcimadamore@852 | 69 | private DiagnosticPosition currentPos; |
mcimadamore@852 | 70 | private Map<DiagnosticPosition, ListBuffer<LintLogger>> loggersQueue = new HashMap<DiagnosticPosition, ListBuffer<LintLogger>>(); |
mcimadamore@852 | 71 | |
jlahoda@2028 | 72 | /**Associate the given logger with the current position as set by {@link #setPos(DiagnosticPosition) }. |
jlahoda@2028 | 73 | * Will be invoked when {@link #flush(DiagnosticPosition) } will be invoked with the same position. |
jlahoda@2028 | 74 | * <br> |
jlahoda@2028 | 75 | * Will invoke the logger synchronously if {@link #immediate() } was called |
jlahoda@2028 | 76 | * instead of {@link #setPos(DiagnosticPosition) }. |
jlahoda@2028 | 77 | */ |
mcimadamore@852 | 78 | public void report(LintLogger logger) { |
jlahoda@2028 | 79 | if (currentPos == IMMEDIATE_POSITION) { |
jlahoda@2028 | 80 | logger.report(); |
jlahoda@2028 | 81 | } else { |
jlahoda@2028 | 82 | ListBuffer<LintLogger> loggers = loggersQueue.get(currentPos); |
jlahoda@2028 | 83 | if (loggers == null) { |
alundblad@2047 | 84 | loggersQueue.put(currentPos, loggers = new ListBuffer<>()); |
jlahoda@2028 | 85 | } |
jlahoda@2028 | 86 | loggers.append(logger); |
jlahoda@2028 | 87 | } |
mcimadamore@852 | 88 | } |
mcimadamore@852 | 89 | |
jlahoda@2028 | 90 | /**Invoke all {@link LintLogger}s that were associated with the provided {@code pos}. |
jlahoda@2028 | 91 | */ |
mcimadamore@852 | 92 | public void flush(DiagnosticPosition pos) { |
mcimadamore@852 | 93 | ListBuffer<LintLogger> loggers = loggersQueue.get(pos); |
mcimadamore@852 | 94 | if (loggers != null) { |
mcimadamore@852 | 95 | for (LintLogger lintLogger : loggers) { |
mcimadamore@852 | 96 | lintLogger.report(); |
mcimadamore@852 | 97 | } |
mcimadamore@852 | 98 | loggersQueue.remove(pos); |
mcimadamore@852 | 99 | } |
mcimadamore@852 | 100 | } |
mcimadamore@852 | 101 | |
jlahoda@2028 | 102 | /**Sets the current position to the provided {@code currentPos}. {@link LintLogger}s |
jlahoda@2028 | 103 | * passed to subsequent invocations of {@link #report(LintLogger) } will be associated |
jlahoda@2028 | 104 | * with the given position. |
jlahoda@2028 | 105 | */ |
jlahoda@2028 | 106 | public DiagnosticPosition setPos(DiagnosticPosition currentPos) { |
jlahoda@2028 | 107 | DiagnosticPosition prevPosition = this.currentPos; |
mcimadamore@852 | 108 | this.currentPos = currentPos; |
jlahoda@2028 | 109 | return prevPosition; |
mcimadamore@852 | 110 | } |
mcimadamore@852 | 111 | |
jlahoda@2028 | 112 | /**{@link LintLogger}s passed to subsequent invocations of |
jlahoda@2028 | 113 | * {@link #report(LintLogger) } will be invoked immediately. |
jlahoda@2028 | 114 | */ |
jlahoda@2028 | 115 | public DiagnosticPosition immediate() { |
jlahoda@2028 | 116 | return setPos(IMMEDIATE_POSITION); |
jlahoda@2028 | 117 | } |
jlahoda@2028 | 118 | |
jlahoda@2028 | 119 | private static final DiagnosticPosition IMMEDIATE_POSITION = new DiagnosticPosition() { |
mcimadamore@852 | 120 | @Override |
jlahoda@2028 | 121 | public JCTree getTree() { |
jlahoda@2028 | 122 | Assert.error(); |
jlahoda@2028 | 123 | return null; |
jlahoda@2028 | 124 | } |
jlahoda@2028 | 125 | |
jlahoda@2028 | 126 | @Override |
jlahoda@2028 | 127 | public int getStartPosition() { |
jlahoda@2028 | 128 | Assert.error(); |
jlahoda@2028 | 129 | return -1; |
jlahoda@2028 | 130 | } |
jlahoda@2028 | 131 | |
jlahoda@2028 | 132 | @Override |
jlahoda@2028 | 133 | public int getPreferredPosition() { |
jlahoda@2028 | 134 | Assert.error(); |
jlahoda@2028 | 135 | return -1; |
jlahoda@2028 | 136 | } |
jlahoda@2028 | 137 | |
jlahoda@2028 | 138 | @Override |
jlahoda@2028 | 139 | public int getEndPosition(EndPosTable endPosTable) { |
jlahoda@2028 | 140 | Assert.error(); |
jlahoda@2028 | 141 | return -1; |
mcimadamore@852 | 142 | } |
mcimadamore@852 | 143 | }; |
mcimadamore@852 | 144 | } |