langtools/src/jdk.jshell/share/classes/jdk/jshell/execution/ExecutionControlForwarder.java
changeset 40512 b9359154240c
parent 39807 ba0ff343d241
child 43132 6a5c69926e60
equal deleted inserted replaced
40511:1b3c502e0bdc 40512:b9359154240c
    42  * Forwards commands from the input to the specified {@link ExecutionControl}
    42  * Forwards commands from the input to the specified {@link ExecutionControl}
    43  * instance, then responses back on the output.
    43  * instance, then responses back on the output.
    44  */
    44  */
    45 class ExecutionControlForwarder {
    45 class ExecutionControlForwarder {
    46 
    46 
       
    47     /**
       
    48      * Maximum number of characters for writeUTF().  Byte maximum is 65535, at
       
    49      * maximum three bytes per character that is 65535 / 3 == 21845.  Minus one
       
    50      * for safety.
       
    51      */
       
    52     private static final int MAX_UTF_CHARS = 21844;
       
    53 
    47     private final ExecutionControl ec;
    54     private final ExecutionControl ec;
    48     private final ObjectInput in;
    55     private final ObjectInput in;
    49     private final ObjectOutput out;
    56     private final ObjectOutput out;
    50 
    57 
    51     ExecutionControlForwarder(ExecutionControl ec, ObjectInput in, ObjectOutput out) {
    58     ExecutionControlForwarder(ExecutionControl ec, ObjectInput in, ObjectOutput out) {
    87     }
    94     }
    88 
    95 
    89     private void writeUTF(String s) throws IOException {
    96     private void writeUTF(String s) throws IOException {
    90         if (s == null) {
    97         if (s == null) {
    91             s = "";
    98             s = "";
       
    99         } else if (s.length() > MAX_UTF_CHARS) {
       
   100             // Truncate extremely long strings to prevent writeUTF from crashing the VM
       
   101             s = s.substring(0, MAX_UTF_CHARS);
    92         }
   102         }
    93         out.writeUTF(s);
   103         out.writeUTF(s);
    94     }
   104     }
    95 
   105 
    96     private void flush() throws IOException {
   106     private void flush() throws IOException {