changeset 1173:adcd0af0a03b

7901363: @Benchmark methods with the same name, but different signatures should yield a proper error message
author shade
date Tue, 31 Mar 2015 18:05:56 +0300
parents fceec061059d
children 406b03c83e5e
files jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/ArgumentListAmbiguityTest.java jmh-core/src/main/java/org/openjdk/jmh/generators/core/MethodGroup.java jmh-core/src/main/java/org/openjdk/jmh/generators/core/MethodInvocation.java
diffstat 3 files changed, 58 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/benchmark/args/ArgumentListAmbiguityTest.java	Tue Mar 31 18:05:56 2015 +0300
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jmh.ct.benchmark.args;
+
+import org.junit.Test;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.ct.CompileTest;
+import org.openjdk.jmh.infra.Blackhole;
+
+public class ArgumentListAmbiguityTest {
+
+    @Benchmark
+    public void test() {
+
+    }
+
+    @Benchmark
+    public void test(Blackhole bh) {
+
+    }
+
+    @Test
+    public void compileTest() {
+        CompileTest.assertFail(this.getClass(), "uniquely named method");
+    }
+
+}
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/core/MethodGroup.java	Tue Mar 31 17:33:03 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/core/MethodGroup.java	Tue Mar 31 18:05:56 2015 +0300
@@ -24,6 +24,7 @@
  */
 package org.openjdk.jmh.generators.core;
 
+import org.openjdk.jmh.annotations.Benchmark;
 import org.openjdk.jmh.annotations.Fork;
 import org.openjdk.jmh.annotations.Measurement;
 import org.openjdk.jmh.annotations.Mode;
@@ -87,7 +88,11 @@
     }
 
     public void addMethod(MethodInfo method, int threads) {
-        methods.add(new MethodInvocation(method, threads));
+        if (!methods.add(new MethodInvocation(method, threads))) {
+            throw new GenerationException(
+                    "Duplicate @" + Benchmark.class.getSimpleName() + " method. JMH needs an uniquely named method, regardless of the arguments list.",
+                    method);
+        }
     }
 
     public Collection<MethodInfo> methods() {
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/core/MethodInvocation.java	Tue Mar 31 17:33:03 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/core/MethodInvocation.java	Tue Mar 31 18:05:56 2015 +0300
@@ -35,7 +35,7 @@
 
     @Override
     public int compareTo(MethodInvocation o) {
-        return method.compareTo(o.method);
+        return method.getName().compareTo(o.method.getName());
     }
 
     @Override
@@ -45,13 +45,13 @@
 
         MethodInvocation that = (MethodInvocation) o;
 
-        if (!method.equals(that.method)) return false;
+        if (!method.getName().equals(that.method.getName())) return false;
 
         return true;
     }
 
     @Override
     public int hashCode() {
-        return method.hashCode();
+        return method.getName().hashCode();
     }
 }