JDK-6270734 : (ann) Serialized form of annotations persists objects from sun.* packages
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • Submitted: 2005-05-16
  • Updated: 2024-04-12
  • Resolved: 2023-09-20
Related Reports
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Win98SE

A DESCRIPTION OF THE PROBLEM :
When an annotation is persisted, the serialized form contains a reference to sun.reflect.annotation.AnnotationInvocationHandler. This is a non-standard class, and may not be present if the object is deserialized on another machine with a non-Sun Java platform, leading to an error.

Further, as sun.* packages are not guaranteed to be compatible across JDK releases, annotations serialzed with one version are not guaranteed to work in the next. And yet the spec says that annotations are meant to be fully serializable.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See the source below

ACTUAL -
The output file contained the serialized object from the sun.* package

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.*;
import java.lang.annotation.*;

@Y
public abstract class X {
    public static void main(String[] args) throws Exception {
        Object ann = X.class.getAnnotation(Y.class);
        ObjectOutputStream os = new ObjectOutputStream(
            new FileOutputStream("x.ser"));
        os.writeObject(ann);
        os.close();
    }
}

@Retention(RetentionPolicy.RUNTIME)
@interface Y { }


---------- END SOURCE ----------
###@###.### 2005-05-16 09:00:52 GMT

Comments
Disproportionately large effort to address an issue with limited impact. Closing as will not fix.
20-09-2023

This issue will need to be re-examined in the context of Project Jigsaw.
13-08-2013

EVALUATION Recategorizing to classes_lang for evaluation because this issue is specific to how annotations (that are visible at runtime) are implemented. ###@###.### 2005-05-17 01:16:31 GMT
17-05-2005