8280798: com.sun.jdi.ObjectReference::setValue spec should prohibit any final field modification

Reviewed-by: alanb, cjplummer, sspitsyn
This commit is contained in:
Alex Menkov 2022-12-02 20:16:51 +00:00
parent fb6fd03233
commit 2821fa9883
4 changed files with 35 additions and 15 deletions

View File

@ -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
@ -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
@ -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

View File

@ -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
@ -45,7 +45,7 @@ import nsk.share.jdi.*;
* <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 =
@ -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",
@ -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;
@ -141,16 +151,16 @@ public class setvalue004 {
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 + "\"");
@ -161,7 +171,7 @@ public class setvalue004 {
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 + "\"");

View File

@ -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
@ -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

View File

@ -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
@ -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);
}