Skip to content

Commit

Permalink
8280798: com.sun.jdi.ObjectReference::setValue spec should prohibit a…
Browse files Browse the repository at this point in the history
…ny final field modification

Reviewed-by: alanb, cjplummer, sspitsyn
  • Loading branch information
Alex Menkov committed Dec 2, 2022
1 parent fb6fd03 commit 2821fa9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/jdk.jdi/share/classes/com/sun/jdi/ObjectReference.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2022, 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 @@ -114,7 +114,7 @@ public interface ObjectReference extends Value {
* Sets the value of a given instance or static field in this object.
* The {@link Field} must be valid for this ObjectReference; that is,
* it must be from the mirrored object's class or a superclass of that class.
* If static, the field must not be final.
* The field must not be final.
* <p>
* Object values must be assignment compatible with the field type
* (This implies that the field type must be loaded through the
Expand All @@ -129,7 +129,7 @@ public interface ObjectReference extends Value {
* @param field the field containing the requested value
* @param value the new value to assign
* @throws java.lang.IllegalArgumentException if the field is not valid for
* this object's class.
* this object's class or the field is final.
* @throws InvalidTypeException if the value's type does not match
* the field's type.
* @throws ClassNotLoadedException if 'value' is not null, and the field
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2022, 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 @@ -45,7 +45,7 @@
* <code>com.sun.jdi.ObjectReference.setValue()</code>
* properly throws <i>IllegalArgumentException</i> when a
* debugger part of the test attempts to set value of
* debuggee's static field which is declared as final.<br>
* debuggee's final field.
*/
public class setvalue004 {
static final String DEBUGGEE_CLASS =
Expand All @@ -62,8 +62,8 @@ public class setvalue004 {
static final String COMMAND_READY = "ready";
static final String COMMAND_QUIT = "quit";

static final int FLDS_NUM = 9;
static final String DEBUGGEE_FLDS[] = {
// static final fields
"sByteFld",
"sShortFld",
"sIntFld",
Expand All @@ -72,7 +72,17 @@ public class setvalue004 {
"sDoubleFld",
"sCharFld",
"sBooleanFld",
"sStrFld"
"sStrFld",
// instance final fields
"iByteFld",
"iShortFld",
"iIntFld",
"iLongFld",
"iFloatFld",
"iDoubleFld",
"iCharFld",
"iBooleanFld",
"iStrFld"
};

private Log log;
Expand Down Expand Up @@ -141,16 +151,16 @@ private int runIt(String args[], PrintStream out) {
rType = objRef.referenceType();

// provoke the IllegalArgumentException
for (int i=0; i<FLDS_NUM; i++) {
for (int i = 0; i < DEBUGGEE_FLDS.length; i++) {
Field fld = rType.fieldByName(DEBUGGEE_FLDS[i]);
try {
log.display("\nTrying to set value for the static final field \""
log.display("\nTrying to set value for the final field \""
+ fld.name() + "\"\n\tfrom the object reference \""
+ objRef + "\" ...");
objRef.setValue(fld,
objRef.getValue(rType.fieldByName(fld.name())));
log.complain("TEST FAILED: expected IllegalArgumentException was not thrown"
+ "\n\twhen attempted to set value for the static final field \""
+ "\n\twhen attempted to set value for the final field \""
+ fld.name() + "\" of " + fld.type() + " type \""
+ "\"\n\tgotten from the debuggee's object reference \""
+ objRef + "\"");
Expand All @@ -161,7 +171,7 @@ private int runIt(String args[], PrintStream out) {
e.printStackTrace();
log.complain("TEST FAILED: ObjectReference.setValue(): caught unexpected "
+ e + "\n\tinstead of expected IllegalArgumentException"
+ "\n\twhen attempted to set value for the static final field \""
+ "\n\twhen attempted to set value for the final field \""
+ fld.name() + "\" of " + fld.type() + " type \""
+ "\"\n\tgotten from the debuggee's object reference \""
+ objRef + "\"");
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2022, 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 @@ -32,8 +32,7 @@
* This test checks that the JDI method
* com.sun.jdi.ObjectReference.setValue() properly throws
* IllegalArgumentException when a debugger part of the test
* attempts to set value of debuggee's static field which
* is declared as final.
* attempts to set value of debuggee's final field.
* COMMENTS
*
* @library /vmTestbase
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2022, 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 @@ -42,6 +42,17 @@ public class setvalue004t {
static final boolean sBooleanFld = false;
static final String sStrFld = "instance field";

// tested instance final fields
final byte iByteFld = 127;
final short iShortFld = -32768;
final int iIntFld = 2147483647;
final long iLongFld = 9223372036854775807L;
final float iFloatFld = 5.1F;
final double iDoubleFld = 6.2D;
final char iCharFld = 'a';
final boolean iBooleanFld = false;
final String iStrFld = "instance field";

public static void main(String args[]) {
System.exit(run(args) + Consts.JCK_STATUS_BASE);
}
Expand Down

1 comment on commit 2821fa9

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.