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

8202056: Expand serial warning to check for bad overloads of serial-related methods and ineffectual fields #5709

Closed
wants to merge 86 commits into from
Closed
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
26e2951
First clean compile.
jddarcy Sep 4, 2021
31885fa
Improve indentation.
jddarcy Sep 4, 2021
b1ad514
Merge branch 'master' into JDK-8202056
jddarcy Sep 7, 2021
594f201
Merge branch 'master' into JDK-8202056
jddarcy Sep 8, 2021
4bd4ece
Merge branch 'master' into JDK-8202056
jddarcy Sep 14, 2021
d3d1e24
Merge branch 'master' into JDK-8202056
jddarcy Sep 18, 2021
1d56f3d
Merge branch 'master' into JDK-8202056
jddarcy Sep 20, 2021
c745e6d
Fix typo in type name.
jddarcy Sep 20, 2021
85ac2b8
Merge branch 'master' into JDK-8202056
jddarcy Sep 21, 2021
d76887e
Compiling again.
jddarcy Sep 23, 2021
992e021
Reduce access of fields.
jddarcy Sep 23, 2021
074d255
Checkpoint.
jddarcy Sep 23, 2021
8a31b62
Six failing tests.
jddarcy Sep 23, 2021
7ae1e71
Add anonymous check.
jddarcy Sep 23, 2021
11f6790
Merge branch 'master' into JDK-8202056
jddarcy Sep 23, 2021
a1c5206
Fix ObjectStreamField check.
jddarcy Sep 23, 2021
2d9384c
Clean test run.
jddarcy Sep 23, 2021
5d6cb23
Add some tests.
jddarcy Sep 24, 2021
56f0955
Improve support for records.
jddarcy Sep 24, 2021
3ff77d3
Improve Externalization warnings.
jddarcy Sep 24, 2021
3d9668f
Add no-arg ctor check for Externalizable classes.
jddarcy Sep 24, 2021
610300a
Add checks for constructor access in Serializable classes.
jddarcy Sep 24, 2021
d0c6dbf
Put Externalizable checks last.
jddarcy Sep 25, 2021
bcbefde
Merge branch 'master' into JDK-8202056
jddarcy Sep 25, 2021
e793124
Clean build with instance field checks in place.
jddarcy Sep 25, 2021
6da3560
Add tests for instance field checks.
jddarcy Sep 26, 2021
4aca7b2
Update comment.
jddarcy Sep 26, 2021
c9bc36a
Implement checks chegar recommended for interfaces.
jddarcy Sep 27, 2021
d498ff5
Appease jcheck
jddarcy Sep 27, 2021
053de6b
Merge branch 'master' into JDK-8202056
jddarcy Sep 27, 2021
11ae5b0
Restore serial checks on java.xml module.
jddarcy Sep 28, 2021
4652ba4
Merge branch 'master' into JDK-8202056
jddarcy Sep 28, 2021
bacff4e
Merge branch 'master' into JDK-8202056
jddarcy Sep 28, 2021
651c68e
Merge branch 'master' into JDK-8202056
jddarcy Sep 28, 2021
37ad877
Fix whitespace.
jddarcy Sep 28, 2021
33504e8
Merge branch 'master' into JDK-8202056
jddarcy Sep 29, 2021
b67754e
Merge branch 'master' into JDK-8202056
jddarcy Sep 30, 2021
dd2fafd
Merge branch 'master' into JDK-8202056
jddarcy Sep 30, 2021
a2f5859
Fix test.
jddarcy Oct 3, 2021
25c1042
Merge branch 'master' into JDK-8202056
jddarcy Oct 3, 2021
d912c92
Make readObject and writeObject methods in tests call default impl.
jddarcy Oct 4, 2021
df18308
Fix typos in properties file; improve implemention in Attr.
jddarcy Oct 5, 2021
ceb1fb2
Remove checkTypeOfField; improve checking for serialPersistentFields.
jddarcy Oct 5, 2021
ddcf358
Merge branch 'master' into JDK-8202056
jddarcy Oct 5, 2021
4bb0e2d
Appease jcheck.
jddarcy Oct 5, 2021
fb8e055
Merge branch 'master' into JDK-8202056
jddarcy Oct 5, 2021
460c9d5
Improve comments for suppressed serial warnings.
jddarcy Oct 5, 2021
1982e2a
More precse compiler.properties message; start refactoring of checkin…
jddarcy Oct 5, 2021
31eefd9
Merge branch 'master' into JDK-8202056
jddarcy Oct 5, 2021
e41fba7
Add resource for checking return type.
jddarcy Oct 5, 2021
294d5e1
Merge branch 'master' into JDK-8202056
jddarcy Oct 5, 2021
82cae46
Fix whitespace.
jddarcy Oct 5, 2021
03d98d2
Improve checking of method modifiers.
jddarcy Oct 6, 2021
01c8836
Improve argument checking.
jddarcy Oct 6, 2021
7a4c195
Favor names in properties; clean up whitespace usage in tests.
jddarcy Oct 6, 2021
91bd896
Merge branch 'master' into JDK-8202056
jddarcy Oct 6, 2021
2bc923f
Improve no-args checking.
jddarcy Oct 6, 2021
f6c1cac
Add thrown type checks.
jddarcy Oct 6, 2021
64c8b2e
Merge branch 'master' into JDK-8202056
jddarcy Oct 7, 2021
9ef6aeb
Adding warning for serial fields in interfaces; cleanup.
jddarcy Oct 7, 2021
96fb1e7
Update test.
jddarcy Oct 7, 2021
1978454
Appease jcheck.
jddarcy Oct 7, 2021
2d72377
Merge branch 'master' into JDK-8202056
jddarcy Oct 7, 2021
2e29638
Add support for checking for serialPersistentFields initialized to a …
jddarcy Oct 7, 2021
f18fa94
Update javac.properties for command-line usage output.
jddarcy Oct 8, 2021
a4c6230
Merge branch 'master' into JDK-8202056
jddarcy Oct 11, 2021
601fb87
Incorporate Jan's refactoring.
jddarcy Oct 11, 2021
d52b5f6
Complete removal of use of javax.lang.model.Modifer.
jddarcy Oct 12, 2021
3a7a0f2
Merge branch 'master' into JDK-8202056
jddarcy Oct 12, 2021
9b6c898
Respond to review feedback; add missing newline.
jddarcy Oct 12, 2021
b7d8161
Improve declared types to remove cast.
jddarcy Oct 13, 2021
48978cf
Initial library updates for array component type check.
jddarcy Oct 13, 2021
3196889
Merge branch 'master' into JDK-8202056
jddarcy Oct 13, 2021
7e92285
Merge branch 'master' into JDK-8202056
jddarcy Oct 13, 2021
64712c6
Merge branch 'master' into JDK-8202056
jddarcy Oct 13, 2021
c8ea34e
Add support for warning on component type of an array.
jddarcy Oct 14, 2021
95d8bb2
Merge branch 'master' into JDK-8202056
jddarcy Oct 18, 2021
e7cf8f4
Sharpen type of method parameters to javac type.
jddarcy Oct 18, 2021
dea009b
Do not warn for prence of serialVersionUID in interfaces.
jddarcy Oct 18, 2021
4750141
Merge branch 'master' into JDK-8202056
jddarcy Oct 19, 2021
6774d68
Clean up imports.
jddarcy Oct 20, 2021
6dd45c4
Improve use of @SuppressWarnings.
jddarcy Oct 20, 2021
91a71f0
Merge branch 'master' into JDK-8202056
jddarcy Oct 20, 2021
9e592a6
Merge branch 'master' into JDK-8202056
jddarcy Oct 21, 2021
9b243cf
Update copyrights; small cleanup.
jddarcy Oct 21, 2021
9e5c753
Merge branch 'master' into JDK-8202056
jddarcy Oct 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -224,6 +224,14 @@ public static Symtab instance(Context context) {
public final Type valueBasedType;
public final Type valueBasedInternalType;

// For serialization lint checking
public final Type objectStreamFieldType;
public final Type objectInputStreamType;
public final Type objectOutputStreamType;
public final Type ioExceptionType;
public final Type objectStreamExceptionType;
public final Type externalizableType;

/** The symbol representing the length field of an array.
*/
public final VarSymbol lengthVar;
@@ -590,6 +598,13 @@ public <R, P> R accept(ElementVisitor<R, P> v, P p) {
switchBootstrapsType = enterClass("java.lang.runtime.SwitchBootstraps");
valueBasedType = enterClass("jdk.internal.ValueBased");
valueBasedInternalType = enterSyntheticAnnotation("jdk.internal.ValueBased+Annotation");
// For serialization lint checking
objectStreamFieldType = enterClass("java.io.ObjectStreamField");
objectInputStreamType = enterClass("java.io.ObjectInputStream");
objectOutputStreamType = enterClass("java.io.ObjectOutputStream");
ioExceptionType = enterClass("java.io.IOException");
objectStreamExceptionType = enterClass("java.io.ObjectStreamException");
externalizableType = enterClass("java.io.Externalizable");

synthesizeEmptyInterfaceIfMissing(autoCloseableType);
synthesizeEmptyInterfaceIfMissing(cloneableType);
@@ -2955,7 +2955,7 @@ private void visitAnonymousClassDefinition(JCNewClass tree, JCExpression clazz,
}

if (resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK &&
isSerializable(clazztype)) {
rs.isSerializable(clazztype)) {
localEnv.info.isSerializable = true;
}

@@ -3080,7 +3080,7 @@ public void visitLambda(final JCLambda that) {
boolean needsRecovery =
resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK;
try {
if (needsRecovery && isSerializable(pt())) {
if (needsRecovery && rs.isSerializable(pt())) {
localEnv.info.isSerializable = true;
localEnv.info.isSerializableLambda = true;
}
@@ -3581,7 +3581,7 @@ public void visitReference(final JCMemberReference that) {

boolean isTargetSerializable =
resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK &&
isSerializable(pt());
rs.isSerializable(pt());
TargetInfo targetInfo = getTargetInfo(that, resultInfo, null);
Type currentTarget = targetInfo.target;
Type desc = targetInfo.descriptor;
@@ -5366,7 +5366,7 @@ void attribClass(ClassSymbol c) throws CompletionFailure {
log.error(env.tree.pos(), Errors.EnumTypesNotExtensible);
}

if (isSerializable(c.type)) {
if (rs.isSerializable(c.type)) {
env.info.isSerializable = true;
}

@@ -5501,12 +5501,12 @@ private void attribClassBody(Env<AttrContext> env, ClassSymbol c) {
// Check for cycles among annotation elements.
chk.checkNonCyclicElements(tree);

// Check for proper use of serialVersionUID
// Check for proper use of serialVersionUID and other
// serialization-related fields and methods
if (env.info.lint.isEnabled(LintCategory.SERIAL)
&& isSerializable(c.type)
&& (c.flags() & (Flags.ENUM | Flags.INTERFACE)) == 0
&& rs.isSerializable(c.type)
&& !c.isAnonymous()) {
checkSerialVersionUID(tree, c, env);
chk.checkSerialStructure(tree, c);
}
if (allowTypeAnnos) {
// Correctly organize the positions of the type annotations
@@ -5527,59 +5527,6 @@ private DiagnosticPosition getDiagnosticPosition(JCClassDecl tree, Type t) {
return null;
}

/** check if a type is a subtype of Serializable, if that is available. */
boolean isSerializable(Type t) {
try {
syms.serializableType.complete();
}
catch (CompletionFailure e) {
return false;
}
return types.isSubtype(t, syms.serializableType);
}

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

// check for presence of serialVersionUID
VarSymbol svuid = null;
for (Symbol sym : c.members().getSymbolsByName(names.serialVersionUID)) {
if (sym.kind == VAR) {
svuid = (VarSymbol)sym;
break;
}
}

if (svuid == null) {
if (!c.isRecord())
log.warning(LintCategory.SERIAL, tree.pos(), Warnings.MissingSVUID(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))
log.warning(LintCategory.SERIAL,
TreeInfo.diagnosticPositionFor(svuid, tree), Warnings.ImproperSVUID(c));

// check that it is long
else if (!svuid.type.hasTag(LONG))
log.warning(LintCategory.SERIAL,
TreeInfo.diagnosticPositionFor(svuid, tree), Warnings.LongSVUID(c));

// check constant
else if (svuid.getConstValue() == null)
log.warning(LintCategory.SERIAL,
TreeInfo.diagnosticPositionFor(svuid, tree), Warnings.ConstantSVUID(c));
}

private Type capture(Type type) {
return types.capture(type);
}