mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-18 06:15:16 +00:00
8191637: Interface with defaults invalid compiler warning for Serializable
Reviewed-by: vromero
This commit is contained in:
parent
8fe5e17e40
commit
b1c9eceaf5
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. 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
|
||||
@ -4743,9 +4743,8 @@ public class Attr extends JCTree.Visitor {
|
||||
// Check for proper use of serialVersionUID
|
||||
if (env.info.lint.isEnabled(LintCategory.SERIAL)
|
||||
&& isSerializable(c.type)
|
||||
&& (c.flags() & Flags.ENUM) == 0
|
||||
&& !c.isAnonymous()
|
||||
&& checkForSerial(c)) {
|
||||
&& (c.flags() & (Flags.ENUM | Flags.INTERFACE)) == 0
|
||||
&& !c.isAnonymous()) {
|
||||
checkSerialVersionUID(tree, c);
|
||||
}
|
||||
if (allowTypeAnnos) {
|
||||
@ -4757,17 +4756,6 @@ public class Attr extends JCTree.Visitor {
|
||||
}
|
||||
}
|
||||
// where
|
||||
boolean checkForSerial(ClassSymbol c) {
|
||||
if ((c.flags() & ABSTRACT) == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return c.members().anyMatch(anyNonAbstractOrDefaultMethod);
|
||||
}
|
||||
}
|
||||
|
||||
public static final Filter<Symbol> anyNonAbstractOrDefaultMethod = s ->
|
||||
s.kind == MTH && (s.flags() & (DEFAULT | ABSTRACT)) != ABSTRACT;
|
||||
|
||||
/** get a diagnostic position for an attribute of Type t, or null if attribute missing */
|
||||
private DiagnosticPosition getDiagnosticPosition(JCClassDecl tree, Type t) {
|
||||
for(List<JCAnnotation> al = tree.mods.annotations; !al.isEmpty(); al = al.tail) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. 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
|
||||
@ -23,26 +23,31 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6356530
|
||||
* @summary -Xlint:serial does not flag abstract classes with concrete methods/members
|
||||
* @compile/fail/ref=SerializableAbstractClassWithNonAbstractMethodsTest.out -XDrawDiagnostics -Werror -Xlint:serial SerializableAbstractClassWithNonAbstractMethodsTest.java
|
||||
* @bug 6356530 8191637
|
||||
* @summary -Xlint:serial does not flag abstract classes with persisent fields
|
||||
* @compile/fail/ref=SerializableAbstractClassTest.out -XDrawDiagnostics -Werror -Xlint:serial SerializableAbstractClassTest.java
|
||||
*/
|
||||
|
||||
abstract class SerializableAbstractClassWithNonAbstractMethodsTest implements java.io.Serializable {
|
||||
void m1() {}
|
||||
abstract class SerializableAbstractClassTest implements java.io.Serializable {
|
||||
// no serialVersionUID; error
|
||||
abstract void m2();
|
||||
|
||||
abstract class AWithUID implements java.io.Serializable {
|
||||
static abstract class AWithUID implements java.io.Serializable {
|
||||
private static final long serialVersionUID = 0;
|
||||
void m(){}
|
||||
}
|
||||
|
||||
interface I extends java.io.Serializable {
|
||||
// no need for serialVersionUID
|
||||
}
|
||||
|
||||
interface IDefault extends java.io.Serializable {
|
||||
// no need for serialVersionUID
|
||||
default int m() { return 1; }
|
||||
}
|
||||
|
||||
interface IDefaultAndUID extends java.io.Serializable {
|
||||
interface IUID extends java.io.Serializable {
|
||||
// no need for serialVersionUID, but not wrong
|
||||
static final long serialVersionUID = 0;
|
||||
default int m() { return 1; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
SerializableAbstractClassTest.java:31:10: compiler.warn.missing.SVUID: SerializableAbstractClassTest
|
||||
- compiler.err.warnings.and.werror
|
||||
1 error
|
||||
1 warning
|
||||
@ -1,5 +0,0 @@
|
||||
SerializableAbstractClassWithNonAbstractMethodsTest.java:40:5: compiler.warn.missing.SVUID: SerializableAbstractClassWithNonAbstractMethodsTest.IDefault
|
||||
SerializableAbstractClassWithNonAbstractMethodsTest.java:31:10: compiler.warn.missing.SVUID: SerializableAbstractClassWithNonAbstractMethodsTest
|
||||
- compiler.err.warnings.and.werror
|
||||
1 error
|
||||
2 warnings
|
||||
Loading…
x
Reference in New Issue
Block a user