Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tls] Rethrow 'IOException' instead of swallowing it #3078

Merged

Conversation

cweitkamp
Copy link
Contributor

@cweitkamp cweitkamp commented Sep 8, 2022

  • Rethrow IOException instead of swallowing it

In case of unreachable servers there is an IOException leading to an error message in the log file. This case can be handled even better when rethrowing the thrown exception which allows the calling instance to react to server side errors.

https://community.openhab.org/t/vizio-tv-binding/138367/12

Signed-off-by: Christoph Weitkamp github@christophweitkamp.de

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
@cweitkamp cweitkamp requested a review from a team as a code owner September 8, 2022 17:12
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/vizio-tv-binding/138367/19

@cweitkamp cweitkamp changed the title [tls] Rethrow 'IOException' instead of swollowing it [tls] Rethrow 'IOException' instead of swallowing it Sep 8, 2022
@cweitkamp cweitkamp added the enhancement An enhancement or new feature of the Core label Sep 8, 2022
*/
public PEMTrustManager(String pemCert) throws CertificateException {
if (!pemCert.isBlank() && pemCert.startsWith(BEGIN_CERT)) {
try (InputStream certInputStream = new ByteArrayInputStream(pemCert.getBytes(StandardCharsets.UTF_8))) {
trustedCert = (X509Certificate) CertificateFactory.getInstance("X.509")
.generateCertificate(certInputStream);
} catch (IOException e) {
throw new CertificateException(e);
LoggerFactory.getLogger(PEMTrustManager.class).debug("An IOException occurred: {}", e.getMessage());
Copy link
Member

Choose a reason for hiding this comment

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

Why is the logger not an instance field? Otherwise LGTM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
@J-N-K J-N-K added this to the 3.4 milestone Sep 10, 2022
@J-N-K J-N-K merged commit f33492d into openhab:main Sep 10, 2022
@cweitkamp cweitkamp deleted the feature-pemtrustmanager-ioexception-handling branch September 10, 2022 18:25
splatch pushed a commit to ConnectorIO/copybara-hab-core that referenced this pull request Jul 12, 2023
* Rethrow IOException instead of swollowing it

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
GitOrigin-RevId: f33492d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature of the Core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants