Skip to content
Permalink
Browse files

8261938: ASN1Formatter.annotate should not return in the finally block

Reviewed-by: rriggs
  • Loading branch information
DamonFool committed Feb 19, 2021
1 parent 977a21a commit b10376bac1136cf225ff9a9bcf892e6d56d4502b
Showing with 14 additions and 5 deletions.
  1. +14 −5 test/lib/jdk/test/lib/hexdump/ASN1Formatter.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, 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
@@ -110,15 +110,24 @@ private ASN1Formatter() {
* A single well formed tagged-value is read and annotated.
*
* @param in a DataInputStream
* @throws IOException if an I/O error occurs
*/
public String annotate(DataInputStream in) throws IOException {
public String annotate(DataInputStream in) {
StringBuilder sb = new StringBuilder();
try {
this.annotate(in, sb);
} finally {
return sb.toString();
} catch (IOException e) {
/*
* Formatters are designed to be nested, where one formatter can call another and the valuable output
* is the formatted string that has been accumulated from the beginning of the stream.
*
* The choice of DataInputStream was chosen for the convenience of the methods to read different types.
* and (declared) exceptions are an unwelcome artifact.
*
* If an exception was percolated up and the formatted output discarded, it would defeat the purpose.
* So we just catch it here and still return useful information about the stream to this point.
*/
}
return sb.toString();
}

/**

1 comment on commit b10376b

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on b10376b Feb 19, 2021

Please sign in to comment.