From 50eb915a74aed2daf03c7d39670d3a1ac8d5cbfb Mon Sep 17 00:00:00 2001 From: Andrey Turbanov Date: Mon, 7 Mar 2022 22:00:11 +0000 Subject: [PATCH] 8282632: Cleanup unnecessary calls to Throwable.initCause() in java.security.jgss Reviewed-by: mullan, rhalade --- .../www/protocol/http/spnego/NegotiatorImpl.java | 10 +++------- .../sun/security/krb5/internal/KRBError.java | 8 +++----- .../krb5/internal/crypto/dk/ArcFourCrypto.java | 13 +++---------- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src/java.security.jgss/share/classes/sun/net/www/protocol/http/spnego/NegotiatorImpl.java b/src/java.security.jgss/share/classes/sun/net/www/protocol/http/spnego/NegotiatorImpl.java index 82f2391816bc2..aa5795448c9b1 100644 --- a/src/java.security.jgss/share/classes/sun/net/www/protocol/http/spnego/NegotiatorImpl.java +++ b/src/java.security.jgss/share/classes/sun/net/www/protocol/http/spnego/NegotiatorImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 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 @@ -127,9 +127,7 @@ public NegotiatorImpl(HttpCallerInfo hci) throws IOException { "fallback to other scheme if allowed. Reason:"); e.printStackTrace(); } - IOException ioe = new IOException("Negotiate support not initiated"); - ioe.initCause(e); - throw ioe; + throw new IOException("Negotiate support not initiated", e); } } @@ -157,9 +155,7 @@ public byte[] nextToken(byte[] token) throws IOException { System.out.println("Negotiate support cannot continue. Reason:"); e.printStackTrace(); } - IOException ioe = new IOException("Negotiate support cannot continue"); - ioe.initCause(e); - throw ioe; + throw new IOException("Negotiate support cannot continue", e); } } } diff --git a/src/java.security.jgss/share/classes/sun/security/krb5/internal/KRBError.java b/src/java.security.jgss/share/classes/sun/security/krb5/internal/KRBError.java index 9350521609034..206bbfc46f5e7 100644 --- a/src/java.security.jgss/share/classes/sun/security/krb5/internal/KRBError.java +++ b/src/java.security.jgss/share/classes/sun/security/krb5/internal/KRBError.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 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 @@ -234,10 +234,8 @@ private void parseEData(byte[] data) throws IOException { System.out.println("Unable to parse eData field of KRB-ERROR:\n" + new sun.security.util.HexDumpEncoder().encodeBuffer(data)); } - IOException ioe = new IOException( - "Unable to parse eData field of KRB-ERROR"); - ioe.initCause(e); - throw ioe; + throw new IOException( + "Unable to parse eData field of KRB-ERROR", e); } } else { if (DEBUG) { diff --git a/src/java.security.jgss/share/classes/sun/security/krb5/internal/crypto/dk/ArcFourCrypto.java b/src/java.security.jgss/share/classes/sun/security/krb5/internal/crypto/dk/ArcFourCrypto.java index cb9912df6c287..a8bda6008f698 100644 --- a/src/java.security.jgss/share/classes/sun/security/krb5/internal/crypto/dk/ArcFourCrypto.java +++ b/src/java.security.jgss/share/classes/sun/security/krb5/internal/crypto/dk/ArcFourCrypto.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 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 @@ -29,7 +29,6 @@ import javax.crypto.*; import javax.crypto.spec.*; import java.util.*; -import sun.security.krb5.EncryptedData; import sun.security.krb5.KrbCryptoException; import sun.security.krb5.Confounder; import sun.security.krb5.internal.crypto.KeyUsage; @@ -159,10 +158,7 @@ public byte[] calculateChecksum(byte[] baseKey, int usage, byte[] input, System.arraycopy(ss, 0, new_ss, 0, ss.length); Ksign = getHmac(baseKey, new_ss); } catch (Exception e) { - GeneralSecurityException gse = - new GeneralSecurityException("Calculate Checkum Failed!"); - gse.initCause(e); - throw gse; + throw new GeneralSecurityException("Calculate Checksum Failed!", e); } // get the salt using key usage @@ -173,10 +169,7 @@ public byte[] calculateChecksum(byte[] baseKey, int usage, byte[] input, try { messageDigest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { - GeneralSecurityException gse = - new GeneralSecurityException("Calculate Checkum Failed!"); - gse.initCause(e); - throw gse; + throw new GeneralSecurityException("Calculate Checksum Failed!", e); } messageDigest.update(salt); messageDigest.update(input, start, len);