### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java,v retrieving revision 1.105 diff -u -r1.105 ReferenceBinding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java 23 Oct 2006 16:48:39 -0000 1.105 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java 7 Nov 2006 16:16:05 -0000 @@ -370,6 +370,8 @@ this.id = TypeIds.T_JavaUtilIterator; else if (CharOperation.equals(TypeConstants.JAVA_IO_SERIALIZABLE, this.compoundName)) this.id = TypeIds.T_JavaIoSerializable; + else if (CharOperation.equals(TypeConstants.JAVA_IO_EXTERNALIZABLE, this.compoundName)) + this.id = TypeIds.T_JavaIoExternalizable; return; } Index: compiler/org/eclipse/jdt/internal/compiler/lookup/TypeIds.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeIds.java,v retrieving revision 1.28 diff -u -r1.28 TypeIds.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/TypeIds.java 29 Mar 2006 02:45:27 -0000 1.28 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/TypeIds.java 7 Nov 2006 16:16:05 -0000 @@ -83,6 +83,8 @@ final int T_JavaLangReflectField = 54; final int T_JavaLangReflectMethod = 55; + final int T_JavaIoExternalizable = 56; + final int NoId = Integer.MAX_VALUE; public static final int IMPLICIT_CONVERSION_MASK = 0xFF; Index: compiler/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java,v retrieving revision 1.43 diff -u -r1.43 TypeConstants.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java 6 Jul 2006 11:20:36 -0000 1.43 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java 7 Nov 2006 16:16:05 -0000 @@ -118,12 +118,17 @@ char[][] JAVA_LANG_ANNOTATION_ELEMENTTYPE = {JAVA, LANG, ANNOTATION, "ElementType".toCharArray()}; //$NON-NLS-1$ char[][] JAVA_LANG_REFLECT_FIELD = new char[][] {JAVA, LANG, REFLECT, "Field".toCharArray()}; //$NON-NLS-1$ char[][] JAVA_LANG_REFLECT_METHOD = new char[][] {JAVA, LANG, REFLECT, "Method".toCharArray()}; //$NON-NLS-1$ + char[][] JAVA_IO_OBJECTSTREAMEXCEPTION = new char[][] { JAVA, IO, "ObjectStreamException".toCharArray()};//$NON-NLS-1$ + char[][] JAVA_IO_EXTERNALIZABLE = {JAVA, IO, "Externalizable".toCharArray()}; //$NON-NLS-1$ + char[][] JAVA_IO_IOEXCEPTION = new char[][] { JAVA, IO, "IOException".toCharArray()};//$NON-NLS-1$ + char[][] JAVA_IO_OBJECTOUTPUTSTREAM = new char[][] { JAVA, IO, "ObjectOutputStream".toCharArray()}; //$NON-NLS-1$ + char[][] JAVA_IO_OBJECTINPUTSTREAM = new char[][] { JAVA, IO, "ObjectInputStream".toCharArray()}; //$NON-NLS-1$ // Constraints for generic type argument inference int CONSTRAINT_EQUAL = 0; // Actual = Formal int CONSTRAINT_EXTENDS = 1; // Actual << Formal int CONSTRAINT_SUPER = 2; // Actual >> Formal - + // Constants used to perform bound checks int OK = 0; int UNCHECKED = 1; Index: compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java,v retrieving revision 1.128 diff -u -r1.128 TypeDeclaration.java --- compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java 28 Oct 2006 04:11:27 -0000 1.128 +++ compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java 7 Nov 2006 16:16:05 -0000 @@ -944,8 +944,51 @@ this.scope.compilerOptions().getSeverity(CompilerOptions.MissingSerialVersion) != ProblemSeverities.Ignore && sourceType.isClass() && !sourceType.isAbstract() + && sourceType.findSuperTypeErasingTo(TypeIds.T_JavaIoExternalizable, false /*Serializable is not a class*/) == null && sourceType.findSuperTypeErasingTo(TypeIds.T_JavaIoSerializable, false /*Serializable is not a class*/) != null; - + + if (needSerialVersion) { + // if Object writeReplace() throws java.io.ObjectStreamException is present, then no serialVersionUID is needed + // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=101476 + CompilationUnitScope compilationUnitScope = this.scope.compilationUnitScope(); + MethodBinding methodBinding = sourceType.getExactMethod(TypeConstants.WRITEREPLACE, new TypeBinding[0], compilationUnitScope); + if (methodBinding != null + && methodBinding.isValidBinding() + && methodBinding.returnType == this.scope.getJavaLangObject()) { + ReferenceBinding[] throwsExceptions = methodBinding.thrownExceptions; + needSerialVersion = throwsExceptions.length != 1 + || !CharOperation.equals(throwsExceptions[0].compoundName, TypeConstants.JAVA_IO_OBJECTSTREAMEXCEPTION); + } + if (needSerialVersion) { + // check the presence of an implementation of the methods + // private void writeObject(java.io.ObjectOutputStream out) throws IOException + // private void readObject(java.io.ObjectInputStream out) throws IOException + boolean hasWriteObjectMethod = false; + boolean hasReadObjectMethod = false; + TypeBinding argumentTypeBinding = this.scope.getType(TypeConstants.JAVA_IO_OBJECTOUTPUTSTREAM, 3); + ReferenceBinding[] throwsExceptions; + if (argumentTypeBinding.isValidBinding()) { + methodBinding = sourceType.getExactMethod(TypeConstants.WRITEOBJECT, new TypeBinding[] { argumentTypeBinding }, compilationUnitScope); + hasWriteObjectMethod = methodBinding != null + && methodBinding.isValidBinding() + && methodBinding.modifiers == ClassFileConstants.AccPrivate + && methodBinding.returnType == TypeBinding.VOID + && (throwsExceptions = methodBinding.thrownExceptions).length == 1 + && CharOperation.equals(throwsExceptions[0].compoundName, TypeConstants.JAVA_IO_IOEXCEPTION); + } + argumentTypeBinding = this.scope.getType(TypeConstants.JAVA_IO_OBJECTINPUTSTREAM, 3); + if (argumentTypeBinding.isValidBinding()) { + methodBinding = sourceType.getExactMethod(TypeConstants.READOBJECT, new TypeBinding[] { argumentTypeBinding }, compilationUnitScope); + hasReadObjectMethod = methodBinding != null + && methodBinding.isValidBinding() + && methodBinding.modifiers == ClassFileConstants.AccPrivate + && methodBinding.returnType == TypeBinding.VOID + && (throwsExceptions = methodBinding.thrownExceptions).length == 1 + && CharOperation.equals(throwsExceptions[0].compoundName, TypeConstants.JAVA_IO_IOEXCEPTION); + } + needSerialVersion = !hasWriteObjectMethod || !hasReadObjectMethod; + } + } // generics (and non static generic members) cannot extend Throwable if (sourceType.findSuperTypeErasingTo(TypeIds.T_JavaLangThrowable, true) != null) { ReferenceBinding current = sourceType;