Skip to content

Commit

Permalink
8231622: SuppressWarning(serial) ignored on field serialVersionUID
Browse files Browse the repository at this point in the history
  • Loading branch information
lgxbslgx committed Dec 4, 2020
1 parent ae1eb28 commit 877e4b8
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 2 deletions.
Expand Up @@ -5338,7 +5338,7 @@ private void attribClassBody(Env<AttrContext> env, ClassSymbol c) {
&& isSerializable(c.type)
&& (c.flags() & (Flags.ENUM | Flags.INTERFACE)) == 0
&& !c.isAnonymous()) {
checkSerialVersionUID(tree, c);
checkSerialVersionUID(tree, c, env);
}
if (allowTypeAnnos) {
// Correctly organize the positions of the type annotations
Expand Down Expand Up @@ -5371,7 +5371,7 @@ boolean isSerializable(Type t) {
}

/** Check that an appropriate serialVersionUID member is defined. */
private void checkSerialVersionUID(JCClassDecl tree, ClassSymbol c) {
private void checkSerialVersionUID(JCClassDecl tree, ClassSymbol c, Env<AttrContext> env) {

// check for presence of serialVersionUID
VarSymbol svuid = null;
Expand All @@ -5388,6 +5388,13 @@ private void checkSerialVersionUID(JCClassDecl tree, ClassSymbol c) {
return;
}

// Check if @SuppressWarnings("serial") is an annotation of serialVersionUID.
// See JDK-8231622 for more information.
Lint lint = env.info.lint.augment(svuid);
if (lint.isSuppressed(LintCategory.SERIAL)) {
return;
}

// check that it is static final
if ((svuid.flags() & (STATIC | FINAL)) !=
(STATIC | FINAL))
Expand Down
35 changes: 35 additions & 0 deletions test/langtools/tools/javac/T8231622/T8231622_1.java
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2020, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* @test
* @bug 8231622
* @summary SuppressWarning("serial") ignored on field serialVersionUID.
* @run compile/ref=T8231622_1.out -XDrawDiagnostics -Xlint:serial T8231622_1.java
*/

import java.io.Serializable;

class T8231622_1 implements Serializable {
public static final int serialVersionUID = 1;
}
2 changes: 2 additions & 0 deletions test/langtools/tools/javac/T8231622/T8231622_1.out
@@ -0,0 +1,2 @@
T8231622_1.java:34:29: compiler.warn.long.SVUID: T8231622_1
1 warning
36 changes: 36 additions & 0 deletions test/langtools/tools/javac/T8231622/T8231622_2.java
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2020, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* @test
* @bug 8231622
* @summary SuppressWarning("serial") ignored on field serialVersionUID. T8231622_2.out is intentionally blank.
* @run compile/ref=T8231622_2.out -XDrawDiagnostics -Xlint:serial T8231622_2.java
*/

import java.io.Serializable;

@SuppressWarnings("serial")
class T8231622_2 implements Serializable {
public static final int serialVersionUID = 1;
}
Empty file.
36 changes: 36 additions & 0 deletions test/langtools/tools/javac/T8231622/T8231622_3.java
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2020, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* @test
* @bug 8231622
* @summary SuppressWarning("serial") ignored on field serialVersionUID. T8231622_3.out is intentionally blank.
* @run compile/ref=T8231622_3.out -XDrawDiagnostics -Xlint:serial T8231622_3.java
*/

import java.io.Serializable;

class T8231622_3 implements Serializable {
@SuppressWarnings("serial")
public static final int serialVersionUID = 1;
}
Empty file.

0 comments on commit 877e4b8

Please sign in to comment.