8242330: Arrays should be cloned in several JAAS Callback classes

Reviewed-by: mullan
This commit is contained in:
Weijun Wang 2020-04-14 10:04:05 +08:00
parent d34f732b99
commit 8cd9241448
3 changed files with 132 additions and 25 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2020, 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
@ -122,31 +122,32 @@ public class ConfirmationCallback implements Callback, java.io.Serializable {
/** ERROR message type. */
public static final int ERROR = 2;
/**
* @serial
* @since 1.4
*/
private String prompt;
private final String prompt;
/**
* @serial
* @since 1.4
*/
private int messageType;
private final int messageType;
/**
* @serial
* @since 1.4
*/
private int optionType = UNSPECIFIED_OPTION;
private final int optionType;
/**
* @serial
* @since 1.4
*/
private int defaultOption;
private final int defaultOption;
/**
* @serial
* @since 1.4
*/
private String[] options;
private final String[] options;
/**
* @serial
* @since 1.4
@ -206,8 +207,10 @@ public class ConfirmationCallback implements Callback, java.io.Serializable {
break;
}
this.prompt = null;
this.messageType = messageType;
this.optionType = optionType;
this.options = null;
this.defaultOption = defaultOption;
}
@ -225,7 +228,8 @@ public class ConfirmationCallback implements Callback, java.io.Serializable {
* @param messageType the message type ({@code INFORMATION},
* {@code WARNING} or {@code ERROR}).
*
* @param options the list of confirmation options.
* @param options the list of confirmation options. The array is cloned
* to protect against subsequent modification.
*
* @param defaultOption the default option, represented as an index
* into the {@code options} array.
@ -253,8 +257,10 @@ public class ConfirmationCallback implements Callback, java.io.Serializable {
throw new IllegalArgumentException();
}
this.prompt = null;
this.messageType = messageType;
this.options = options;
this.optionType = UNSPECIFIED_OPTION;
this.options = options.clone();
this.defaultOption = defaultOption;
}
@ -319,6 +325,7 @@ public class ConfirmationCallback implements Callback, java.io.Serializable {
this.prompt = prompt;
this.messageType = messageType;
this.optionType = optionType;
this.options = null;
this.defaultOption = defaultOption;
}
@ -338,7 +345,8 @@ public class ConfirmationCallback implements Callback, java.io.Serializable {
* @param messageType the message type ({@code INFORMATION},
* {@code WARNING} or {@code ERROR}).
*
* @param options the list of confirmation options.
* @param options the list of confirmation options. The array is cloned
* to protect against subsequent modification.
*
* @param defaultOption the default option, represented as an index
* into the {@code options} array.
@ -371,7 +379,8 @@ public class ConfirmationCallback implements Callback, java.io.Serializable {
this.prompt = prompt;
this.messageType = messageType;
this.options = options;
this.optionType = UNSPECIFIED_OPTION;
this.options = options.clone();
this.defaultOption = defaultOption;
}
@ -418,12 +427,12 @@ public class ConfirmationCallback implements Callback, java.io.Serializable {
/**
* Get the confirmation options.
*
* @return the list of confirmation options, or null if this
* @return a copy of the list of confirmation options, or null if this
* {@code ConfirmationCallback} was instantiated with
* an {@code optionType} instead of {@code options}.
*/
public String[] getOptions() {
return options;
return options == null ? null : options.clone();
}
/**