JDK-5047858 : (reflect) Class.getMethod() can't find String[].clone()
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_8
  • CPU: generic
  • Submitted: 2004-05-14
  • Updated: 2012-09-28
  • Resolved: 2004-05-15
Related Reports
Duplicate :  
Description
According to JLS 10.7, every array type has a public clone() method.  The spec
for Class.getMethod() clearly requires such a public method to be returned.
Yet this clone() method is never returned from Class.getMethod().

==========$ cat -n Test.java
     1  class Test {
     2      public static void main(String[] args) throws Exception {
     3          Object argsClone = args.getClass().getMethod("clone").invoke(args);
     4          System.out.println("args = " + args.hashCode());
     5          System.out.println("args = " + argsClone.hashCode());
     6      }
     7  }
==========$ /java/re/j2se/1.5.0/promoted/latest/binaries/`platform`/bin/java -version
java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b51)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b51, mixed mode)
==========$ /java/re/j2se/1.5.0/promoted/latest/binaries/`platform`/bin/javac Test.java
==========$ /java/re/j2se/1.5.0/promoted/latest/binaries/`platform`/bin/java Test
Exception in thread "main" java.lang.NoSuchMethodException: [Ljava.lang.String;.clone()
        at java.lang.Class.getMethod(Class.java:1386)
        at Test.main(Test.java:3)
==========$