6583626: Improve serialization support in javax.lang.model.type exception classes

Reviewed-by: jjg
This commit is contained in:
Joe Darcy 2009-01-16 14:05:55 -08:00
parent b4747d3188
commit 6644396543
2 changed files with 28 additions and 8 deletions

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,8 @@
package javax.lang.model.type; package javax.lang.model.type;
import java.io.ObjectInputStream;
import java.io.IOException;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import javax.lang.model.element.Element; import javax.lang.model.element.Element;
@ -67,4 +68,13 @@ public class MirroredTypeException extends RuntimeException {
public TypeMirror getTypeMirror() { public TypeMirror getTypeMirror() {
return type; return type;
} }
/**
* Explicitly set all transient fields.
*/
private void readObject(ObjectInputStream s)
throws IOException, ClassNotFoundException {
s.defaultReadObject();
type = null;
}
} }

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,12 +25,12 @@
package javax.lang.model.type; package javax.lang.model.type;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Collections; import java.util.Collections;
import java.io.ObjectInputStream;
import java.io.IOException;
import javax.lang.model.element.Element; import javax.lang.model.element.Element;
@ -49,8 +49,7 @@ public class MirroredTypesException extends RuntimeException {
private static final long serialVersionUID = 269; private static final long serialVersionUID = 269;
// Should this be non-final for a custum readObject method? private transient List<? extends TypeMirror> types; // cannot be serialized
private final transient List<? extends TypeMirror> types; // cannot be serialized
/** /**
* Constructs a new MirroredTypesException for the specified types. * Constructs a new MirroredTypesException for the specified types.
@ -58,7 +57,9 @@ public class MirroredTypesException extends RuntimeException {
* @param types the types being accessed * @param types the types being accessed
*/ */
public MirroredTypesException(List<? extends TypeMirror> types) { 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); this.types = Collections.unmodifiableList(types);
} }
@ -72,4 +73,13 @@ public class MirroredTypesException extends RuntimeException {
public List<? extends TypeMirror> getTypeMirrors() { public List<? extends TypeMirror> getTypeMirrors() {
return types; return types;
} }
/**
* Explicitly set all transient fields.
*/
private void readObject(ObjectInputStream s)
throws IOException, ClassNotFoundException {
s.defaultReadObject();
types = null;
}
} }