Skip to content

Commit

Permalink
8231427: Warning cleanup in tests of java.io.Serializable
Browse files Browse the repository at this point in the history
Backport-of: 942402b
  • Loading branch information
Andrew Lu committed Jul 4, 2024
1 parent 91cdddf commit cdfb4e7
Show file tree
Hide file tree
Showing 114 changed files with 625 additions and 313 deletions.
7 changes: 3 additions & 4 deletions test/jdk/java/io/ObjectInputStream/ResolveProxyClass.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2019, 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
Expand Down Expand Up @@ -36,7 +36,6 @@
* @run main ResolveProxyClass
*/

import java.lang.reflect.*;
import java.io.*;

public class ResolveProxyClass {
Expand All @@ -52,7 +51,7 @@ private static class TestObjectInputStream extends ObjectInputStream {
super();
}

protected Class resolveProxyClass(String[] interfaces)
protected Class<?> resolveProxyClass(String[] interfaces)
throws IOException, ClassNotFoundException
{
return super.resolveProxyClass(interfaces);
Expand Down Expand Up @@ -82,7 +81,7 @@ public static void main(String[] args) {
ClassLoader expectedLoader = ResolveProxyClass.class.getClassLoader();

TestObjectInputStream in = new TestObjectInputStream();
Class proxyClass = in.resolveProxyClass(
Class<?> proxyClass = in.resolveProxyClass(
new String[] { Runnable.class.getName() });
ClassLoader proxyLoader = proxyClass.getClassLoader();
System.err.println("proxy class \"" + proxyClass +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2019, 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
Expand Down Expand Up @@ -58,6 +58,8 @@ public static void main(String[] args) throws Exception {
}

static class TestClass implements Serializable {
private static final long serialVersionUID = 1L;

String str = "hello world";
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2019, 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
Expand Down Expand Up @@ -36,7 +36,9 @@ class Foo implements Serializable {
private Float bar;
}

class Gub extends Foo {}
class Gub extends Foo {
private static final long serialVersionUID = 1L;
}

public class Read {
public static void main(String[] args) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2019, 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
Expand Down Expand Up @@ -41,10 +41,12 @@

class Foo implements Serializable {
private static final long serialVersionUID = 0L;
private Integer bar = new Integer(0);
private Integer bar = 0;
}

class Gub extends Foo {}
class Gub extends Foo {
private static final long serialVersionUID = 1L;
}

public class Write {
public static void main(String[] args) throws Exception {
Expand Down
3 changes: 2 additions & 1 deletion test/jdk/java/io/Serializable/GetField/Read2.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2019, 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
Expand Down Expand Up @@ -41,6 +41,7 @@ class Foo implements Serializable {
float f;
double d;
String str;
@SuppressWarnings("serial") /* Incorrect declarations are being tested */
Object extra;

private void readObject(ObjectInputStream in)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2019, 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
Expand Down Expand Up @@ -56,24 +56,33 @@ protected DefaultPackagePrivateConstructor(int i) {
class DefaultPublicSerializable
extends DefaultPackagePublicConstructor implements Serializable
{
private static final long serialVersionUID = 1L;

int field1 = 5;
};

class DefaultProtectedSerializable
extends DefaultPackageProtectedConstructor implements Serializable
{
private static final long serialVersionUID = 1L;

int field1 = 5;
};

class DefaultAccessSerializable
extends DefaultPackageDefaultAccessConstructor implements Serializable
{
private static final long serialVersionUID = 1L;

int field1 = 5;
};

@SuppressWarnings("serial") /* Incorrect declarations are being tested */
class DefaultPrivateSerializable
extends DefaultPackagePrivateConstructor implements Serializable
{
private static final long serialVersionUID = 1L;

int field1 = 5;

DefaultPrivateSerializable() {
Expand All @@ -82,6 +91,8 @@ class DefaultPrivateSerializable
};

class ExternalizablePublicConstructor implements Externalizable {
private static final long serialVersionUID = 1L;

public ExternalizablePublicConstructor() {
}
public void writeExternal(ObjectOutput out) throws IOException {
Expand All @@ -92,7 +103,10 @@ public void readExternal(ObjectInput in)
}
};

@SuppressWarnings("serial") /* Incorrect declarations are being tested */
class ExternalizableProtectedConstructor implements Externalizable {
private static final long serialVersionUID = 1L;

protected ExternalizableProtectedConstructor() {
}
public void writeExternal(ObjectOutput out) throws IOException {
Expand All @@ -103,7 +117,10 @@ public void readExternal(ObjectInput in)
}
};

@SuppressWarnings("serial") /* Incorrect declarations are being tested */
class ExternalizableAccessConstructor implements Externalizable {
private static final long serialVersionUID = 1L;

ExternalizableAccessConstructor() {
}
public void writeExternal(ObjectOutput out) throws IOException {
Expand All @@ -114,7 +131,10 @@ public void readExternal(ObjectInput in)
}
};

@SuppressWarnings("serial") /* Incorrect declarations are being tested */
class ExternalizablePrivateConstructor implements Externalizable {
private static final long serialVersionUID = 1L;

private ExternalizablePrivateConstructor() {
}
public ExternalizablePrivateConstructor(int i) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2019, 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
Expand Down Expand Up @@ -34,18 +34,24 @@
class PublicSerializable
extends NonSerializable.PublicCtor implements Serializable
{
private static final long serialVersionUID = 1L;

int field1 = 5;
};

class ProtectedSerializable
extends NonSerializable.ProtectedCtor implements Serializable
{
private static final long serialVersionUID = 1L;

int field1 = 5;
};

class DifferentPackageSerializable
extends NonSerializable.PackageCtor implements Serializable
{
private static final long serialVersionUID = 1L;

int field1 = 5;
DifferentPackageSerializable() {
super(1);
Expand All @@ -55,24 +61,32 @@ class DifferentPackageSerializable
class SamePackageSerializable
extends Serialize.SamePackageCtor implements Serializable
{
private static final long serialVersionUID = 1L;

SamePackageSerializable() {
}
};

class SamePackageProtectedCtor {
private static final long serialVersionUID = 1L;

protected SamePackageProtectedCtor() {
}
};

class SamePackageProtectedSerializable
extends Serialize.SamePackageProtectedCtor implements Serializable
{
private static final long serialVersionUID = 1L;

SamePackageProtectedSerializable() {
}
};


class SamePackagePrivateCtor {
private static final long serialVersionUID = 1L;

private SamePackagePrivateCtor() {
}
public SamePackagePrivateCtor(int l) {
Expand All @@ -82,6 +96,8 @@ public SamePackagePrivateCtor(int l) {
class SamePackagePrivateSerializable
extends Serialize.SamePackagePrivateCtor implements Serializable
{
private static final long serialVersionUID = 1L;

SamePackagePrivateSerializable() {
super(1);
}
Expand All @@ -90,6 +106,8 @@ class SamePackagePrivateSerializable
class PrivateSerializable
extends NonSerializable.PrivateCtor implements Serializable
{
private static final long serialVersionUID = 1L;

int field1 = 5;

PrivateSerializable() {
Expand All @@ -98,6 +116,8 @@ class PrivateSerializable
};

class ExternalizablePublicCtor implements Externalizable {
private static final long serialVersionUID = 1L;

public ExternalizablePublicCtor() {
}
public void writeExternal(ObjectOutput out) throws IOException {
Expand All @@ -108,7 +128,10 @@ public void readExternal(ObjectInput in)
}
};

@SuppressWarnings("serial") /* Incorrect declarations are being tested */
class ExternalizableProtectedCtor implements Externalizable {
private static final long serialVersionUID = 1L;

protected ExternalizableProtectedCtor() {
}
public void writeExternal(ObjectOutput out) throws IOException {
Expand All @@ -119,7 +142,10 @@ public void readExternal(ObjectInput in)
}
};

@SuppressWarnings("serial") /* Incorrect declarations are being tested */
class ExternalizablePackageCtor implements Externalizable {
private static final long serialVersionUID = 1L;

ExternalizablePackageCtor() {
}
public void writeExternal(ObjectOutput out) throws IOException {
Expand All @@ -130,7 +156,10 @@ public void readExternal(ObjectInput in)
}
};

@SuppressWarnings("serial") /* Incorrect declarations are being tested */
class ExternalizablePrivateCtor implements Externalizable {
private static final long serialVersionUID = 1L;

private ExternalizablePrivateCtor() {
}
public ExternalizablePrivateCtor(int i) {
Expand Down
4 changes: 3 additions & 1 deletion test/jdk/java/io/Serializable/NPEProvoker/NPEProvoker.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2019, 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
Expand Down Expand Up @@ -41,6 +41,8 @@
import java.util.ArrayList;

public class NPEProvoker implements java.io.Externalizable {
private static final long serialVersionUID = 1L;

private String test = "test";

public void readExternal(ObjectInput in) throws IOException,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2019, 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
Expand Down Expand Up @@ -40,7 +40,9 @@ public class NoClassDefFoundErrorTrap {
private static NoClassDefFoundError ncdfe;

public interface Bar {}
public static class Foo implements Bar, java.io.Serializable {}
public static class Foo implements Bar, java.io.Serializable {
private static final long serialVersionUID = 1L;
}

/**
* Test subclass of ObjectInputStream that overrides resolveClass
Expand All @@ -55,7 +57,7 @@ public TestObjectInputStream(InputStream in)
super(in);
}

protected Class resolveClass(ObjectStreamClass desc)
protected Class<?> resolveClass(ObjectStreamClass desc)
throws IOException, ClassNotFoundException
{
String name = desc.getName();
Expand Down
3 changes: 2 additions & 1 deletion test/jdk/java/io/Serializable/PutField/Write2.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2019, 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
Expand Down Expand Up @@ -44,6 +44,7 @@ class Foo implements Serializable {
new ObjectStreamField("s2", String.class)
};

@SuppressWarnings("deprecation")
private void writeObject(ObjectOutputStream out) throws IOException {
ObjectOutputStream.PutField fields = out.putFields();
fields.put("s1", "qwerty");
Expand Down
Loading

0 comments on commit cdfb4e7

Please sign in to comment.