United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6516895 : Varargs argument to method or ctor sets 'transient' modifier

Details
Type:
Bug
Submit Date:
2007-01-24
Status:
Closed
Updated Date:
2011-02-16
Project Name:
JDK
Resolved Date:
2007-01-24
Component:
core-libs
OS:
linux
Sub-Component:
java.lang
CPU:
x86
Priority:
P4
Resolution:
Won't Fix
Affected Versions:
6
Fixed Versions:

Related Reports
Relates:
Relates:
Relates:

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.5.0_10"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_10-b03)
Java HotSpot(TM) Client VM (build 1.5.0_10-b03, mixed mode, sharing)

java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
linux 2.6.18.6

A DESCRIPTION OF THE PROBLEM :
When a method or constructor has a varargs argument, the 'transient' modifier is set. This bug appears in JDK 1.5.0_10 and JDK 1.6.0

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Copy the submitted source code to a file named 'showbug.java'. Compile and run.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No output.
ACTUAL -
testclass ctor has illegal transient modifier.
hello has illegal transient modifier.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import static java.lang.reflect.Modifier.*;

class testclass {
        public testclass(int k, float [] f, boolean ... args) {}
        public void hello(boolean ... args) {}
        public void hello2() {}
}

public class showbug {
        public static void main(String [] args) throws Exception {
                Class clazz = Class.forName("testclass");
                Constructor [] ctors = clazz.getDeclaredConstructors();

                // This shows the bug.
                for ( Constructor ctor : ctors ) {
                        if ( (ctor.getModifiers() & TRANSIENT) != 0 ) {
                                System.out.println(ctor.getName() + " ctor has illegal transient modifier.");
                        }
                }

                // This shows the bug.
                Method hello = clazz.getMethod("hello", boolean[].class);
                if ( (hello.getModifiers() & TRANSIENT) != 0 ) {
                        System.out.println(hello.getName() + " has illegal transient modifier.");
                }

                // This works as expected.
                Method hello2 = clazz.getMethod("hello2");
                if ( (hello2.getModifiers() & TRANSIENT) != 0 ) {
                        System.out.println(hello2.getName() + " has illegal transient modifier.");
                }
        }
}
---------- END SOURCE ----------

                                    

Comments
EVALUATION

Yes, the bit used to mark a method or constructor as var-args overlaps with the bit position used to make a field transient.  (A similar overlap occurs with bridge methods and volatile.)  This is documented in the updated JVM specification:

http://java.sun.com/docs/books/vmspec/2nd-edition/ClassFileFormat-Java5.pdf

The Method and Constructor toString methods have been updated to not print out these misleading overlaps.  {Method, Constructor}.isVarArgs() can be used to check for var-arg-ness.

Closing as will not fix.
                                     
2007-01-24



Hardware and Software, Engineered to Work Together