Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDK-8310861: Improve location reporting for javac serial lint warnings #14644

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java
Original file line number Diff line number Diff line change
@@ -5048,16 +5048,19 @@ private void checkSerialPersistentFields(JCClassDecl tree, Element e, VarSymbol
if ((spf.flags() & (PRIVATE | STATIC | FINAL)) !=
(PRIVATE | STATIC | FINAL)) {
log.warning(LintCategory.SERIAL,
TreeInfo.diagnosticPositionFor(spf, tree), Warnings.ImproperSPF);
TreeInfo.diagnosticPositionFor(spf, tree),
Warnings.ImproperSPF);
}

if (!types.isSameType(spf.type, OSF_TYPE)) {
log.warning(LintCategory.SERIAL,
TreeInfo.diagnosticPositionFor(spf, tree), Warnings.OSFArraySPF);
TreeInfo.diagnosticPositionFor(spf, tree),
Warnings.OSFArraySPF);
}

if (isExternalizable((Type)(e.asType()))) {
log.warning(LintCategory.SERIAL, tree.pos(),
log.warning(LintCategory.SERIAL,
TreeInfo.diagnosticPositionFor(spf, tree),
Warnings.IneffectualSerialFieldExternalizable);
}

@@ -5165,15 +5168,19 @@ public Void visitTypeAsEnum(TypeElement e,
String name = enclosed.getSimpleName().toString();
switch(enclosed.getKind()) {
case FIELD -> {
var field = (VarSymbol)enclosed;
if (serialFieldNames.contains(name)) {
log.warning(LintCategory.SERIAL, tree.pos(),
log.warning(LintCategory.SERIAL,
TreeInfo.diagnosticPositionFor(field, tree),
Warnings.IneffectualSerialFieldEnum(name));
}
}

case METHOD -> {
var method = (MethodSymbol)enclosed;
if (serialMethodNames.contains(name)) {
log.warning(LintCategory.SERIAL, tree.pos(),
log.warning(LintCategory.SERIAL,
TreeInfo.diagnosticPositionFor(method, tree),
Warnings.IneffectualSerialMethodEnum(name));
}
}
@@ -5293,17 +5300,19 @@ public Void visitTypeAsRecord(TypeElement e,
String name = enclosed.getSimpleName().toString();
switch(enclosed.getKind()) {
case FIELD -> {
var field = (VarSymbol)enclosed;
switch(name) {
case "serialPersistentFields" -> {
log.warning(LintCategory.SERIAL, tree.pos(),
log.warning(LintCategory.SERIAL,
TreeInfo.diagnosticPositionFor(field, tree),
Warnings.IneffectualSerialFieldRecord);
}

case "serialVersionUID" -> {
// Could generate additional warning that
// svuid value is not checked to match for
// records.
checkSerialVersionUID(tree, e, (VarSymbol)enclosed);
checkSerialVersionUID(tree, e, field);
}

}
@@ -5314,9 +5323,11 @@ public Void visitTypeAsRecord(TypeElement e,
switch(name) {
case "writeReplace" -> checkWriteReplace(tree, e, method);
case "readResolve" -> checkReadResolve(tree, e, method);

default -> {
if (serialMethodNames.contains(name)) {
log.warning(LintCategory.SERIAL, tree.pos(),
log.warning(LintCategory.SERIAL,
TreeInfo.diagnosticPositionFor(method, tree),
Warnings.IneffectualSerialMethodRecord(name));
}
}
@@ -5394,7 +5405,8 @@ private void checkNoArgs(JCClassDecl tree, Element enclosing, MethodSymbol metho
private void checkExternalizable(JCClassDecl tree, Element enclosing, MethodSymbol method) {
// If the enclosing class is externalizable, warn for the method
if (isExternalizable((Type)enclosing.asType())) {
log.warning(LintCategory.SERIAL, tree.pos(),
log.warning(LintCategory.SERIAL,
TreeInfo.diagnosticPositionFor(method, tree),
Warnings.IneffectualSerialMethodExternalizable(method.getSimpleName()));
}
return;
1 change: 1 addition & 0 deletions test/langtools/tools/javac/warnings/Serial/CtorAccess.java
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
* @test /nodynamiccopyright/
* @bug 8202056
* @compile/ref=CtorAccess.out -XDrawDiagnostics -Xlint:serial CtorAccess.java
* @compile/ref=empty.out -XDrawDiagnostics CtorAccess.java
*/

import java.io.*;
4 changes: 2 additions & 2 deletions test/langtools/tools/javac/warnings/Serial/CtorAccess.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
CtorAccess.java:15:12: compiler.warn.serializable.missing.access.no.arg.ctor: CtorAccess
CtorAccess.java:30:5: compiler.warn.serializable.missing.access.no.arg.ctor: CtorAccess.MemberSuper
CtorAccess.java:16:12: compiler.warn.serializable.missing.access.no.arg.ctor: CtorAccess
CtorAccess.java:31:5: compiler.warn.serializable.missing.access.no.arg.ctor: CtorAccess.MemberSuper
2 warnings
1 change: 1 addition & 0 deletions test/langtools/tools/javac/warnings/Serial/EnumSerial.java
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
* @test /nodynamiccopyright/
* @bug 8202056
* @compile/ref=EnumSerial.out -XDrawDiagnostics -Xlint:serial EnumSerial.java
* @compile/ref=empty.out -XDrawDiagnostics EnumSerial.java
*/

import java.io.*;
14 changes: 7 additions & 7 deletions test/langtools/tools/javac/warnings/Serial/EnumSerial.out
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
EnumSerial.java:9:1: compiler.warn.ineffectual.serial.field.enum: serialVersionUID
EnumSerial.java:9:1: compiler.warn.ineffectual.serial.field.enum: serialPersistentFields
EnumSerial.java:9:1: compiler.warn.ineffectual.serial.method.enum: writeObject
EnumSerial.java:9:1: compiler.warn.ineffectual.serial.method.enum: writeReplace
EnumSerial.java:9:1: compiler.warn.ineffectual.serial.method.enum: readObject
EnumSerial.java:9:1: compiler.warn.ineffectual.serial.method.enum: readObjectNoData
EnumSerial.java:9:1: compiler.warn.ineffectual.serial.method.enum: readResolve
EnumSerial.java:16:31: compiler.warn.ineffectual.serial.field.enum: serialVersionUID
EnumSerial.java:17:46: compiler.warn.ineffectual.serial.field.enum: serialPersistentFields
EnumSerial.java:19:18: compiler.warn.ineffectual.serial.method.enum: writeObject
EnumSerial.java:23:20: compiler.warn.ineffectual.serial.method.enum: writeReplace
EnumSerial.java:27:18: compiler.warn.ineffectual.serial.method.enum: readObject
EnumSerial.java:32:18: compiler.warn.ineffectual.serial.method.enum: readObjectNoData
EnumSerial.java:36:20: compiler.warn.ineffectual.serial.method.enum: readResolve
7 warnings
1 change: 1 addition & 0 deletions test/langtools/tools/javac/warnings/Serial/Extern.java
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
* @test /nodynamiccopyright/
* @bug 8202056
* @compile/ref=Extern.out -XDrawDiagnostics -Xlint:serial Extern.java
* @compile/ref=empty.out -XDrawDiagnostics Extern.java
*/

import java.io.*;
10 changes: 5 additions & 5 deletions test/langtools/tools/javac/warnings/Serial/Extern.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Extern.java:9:1: compiler.warn.externalizable.missing.public.no.arg.ctor
Extern.java:9:1: compiler.warn.ineffectual.serial.field.externalizable
Extern.java:9:1: compiler.warn.ineffectual.serial.method.externalizable: readObject
Extern.java:9:1: compiler.warn.ineffectual.serial.method.externalizable: writeObject
Extern.java:9:1: compiler.warn.ineffectual.serial.method.externalizable: readObjectNoData
Extern.java:10:1: compiler.warn.externalizable.missing.public.no.arg.ctor
Extern.java:17:46: compiler.warn.ineffectual.serial.field.externalizable
Extern.java:28:18: compiler.warn.ineffectual.serial.method.externalizable: readObject
Extern.java:34:18: compiler.warn.ineffectual.serial.method.externalizable: writeObject
Extern.java:39:18: compiler.warn.ineffectual.serial.method.externalizable: readObjectNoData
5 warnings
11 changes: 10 additions & 1 deletion test/langtools/tools/javac/warnings/Serial/RecordSerial.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* @test /nodynamiccopyright/
* @bug 8202056
* @bug 8202056 8310861
* @compile/ref=RecordSerial.out -XDrawDiagnostics -Xlint:serial RecordSerial.java
*/

@@ -41,4 +41,13 @@ private void readObjectNoData() throws ObjectStreamException {
private Object readResolve() throws ObjectStreamException {
return null;
}

// meaningless Externalizable methods, no warning generated
public void writeExternal(ObjectOutput oo) {
;
}

public void readExternal(ObjectInput oi) {
;
}
}
8 changes: 4 additions & 4 deletions test/langtools/tools/javac/warnings/Serial/RecordSerial.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RecordSerial.java:9:1: compiler.warn.ineffectual.serial.field.record
RecordSerial.java:9:1: compiler.warn.ineffectual.serial.method.record: writeObject
RecordSerial.java:9:1: compiler.warn.ineffectual.serial.method.record: readObject
RecordSerial.java:9:1: compiler.warn.ineffectual.serial.method.record: readObjectNoData
RecordSerial.java:17:46: compiler.warn.ineffectual.serial.field.record
RecordSerial.java:20:18: compiler.warn.ineffectual.serial.method.record: writeObject
RecordSerial.java:30:18: compiler.warn.ineffectual.serial.method.record: readObject
RecordSerial.java:36:18: compiler.warn.ineffectual.serial.method.record: readObjectNoData
4 warnings