JDK-6583626 : Improve serialization support in javax.lang.model.type exception classes
  • Type: Bug
  • Component: core-libs
  • Sub-Component: javax.lang.model
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2007-07-20
  • Updated: 2014-10-02
  • Resolved: 2011-07-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b46Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
Findbugs reports some warnings based on serialization + final field clashes in the exception types declared in javax.lang.model.type.  These warnings can be addressed by clarifying how those classes are written.

Comments
SUGGESTED FIX --- old/src/share/classes/javax/lang/model/type/MirroredTypeException.java Wed Jan 14 19:01:16 2009 +++ new/src/share/classes/javax/lang/model/type/MirroredTypeException.java Wed Jan 14 19:01:15 2009 @@ -1,5 +1,5 @@ /* - * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2005-2009 Sun Microsystems, Inc. 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 @@ -25,7 +25,8 @@ package javax.lang.model.type; - +import java.io.ObjectInputStream; +import java.io.IOException; import java.lang.annotation.Annotation; import javax.lang.model.element.Element; @@ -67,4 +68,13 @@ public TypeMirror getTypeMirror() { return type; } + + /** + * Explicitly set all transient fields. + */ + private void readObject(ObjectInputStream s) + throws IOException, ClassNotFoundException { + s.defaultReadObject(); + type = null; + } } --- old/src/share/classes/javax/lang/model/type/MirroredTypesException.java Wed Jan 14 19:01:17 2009 +++ new/src/share/classes/javax/lang/model/type/MirroredTypesException.java Wed Jan 14 19:01:17 2009 @@ -1,5 +1,5 @@ /* - * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2005-2009 Sun Microsystems, Inc. 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 @@ -25,12 +25,12 @@ package javax.lang.model.type; - import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.List; import java.util.Collections; - +import java.io.ObjectInputStream; +import java.io.IOException; import javax.lang.model.element.Element; @@ -49,8 +49,7 @@ private static final long serialVersionUID = 269; - // Should this be non-final for a custum readObject method? - private final transient List<? extends TypeMirror> types; // cannot be serialized + private transient List<? extends TypeMirror> types; // cannot be serialized /** * Constructs a new MirroredTypesException for the specified types. @@ -58,7 +57,9 @@ * @param types the types being accessed */ public MirroredTypesException(List<? extends TypeMirror> types) { - super("Attempt to access Class objects for TypeMirrors " + types); + super("Attempt to access Class objects for TypeMirrors " + + (types = // defensive copy + new ArrayList<TypeMirror>(types)).toString() ); this.types = Collections.unmodifiableList(types); } @@ -72,4 +73,13 @@ public List<? extends TypeMirror> getTypeMirrors() { return types; } + + /** + * Explicitly set all transient fields. + */ + private void readObject(ObjectInputStream s) + throws IOException, ClassNotFoundException { + s.defaultReadObject(); + types = null; + } }
2009-01-16

EVALUATION Should be fixed.
2007-07-20