SPARK-2204: Code cleanup: Delete declaration of exceptions that are never thrown

This commit is contained in:
arthur 2020-11-17 00:27:11 +03:00
parent bcd8f0c671
commit ff7175800c
35 changed files with 63 additions and 94 deletions

View File

@ -1272,7 +1272,7 @@ public class LoginDialog {
}
@Override
public void handle(Callback[] callbacks) throws IOException {
public void handle(Callback[] callbacks) {
for (Callback callback : callbacks) {
if (callback instanceof NameCallback) {
NameCallback ncb = (NameCallback) callback;
@ -1363,9 +1363,8 @@ public class LoginDialog {
/**
* Updates System properties with Proxy configuration.
*
* @throws Exception thrown if an exception occurs.
*/
private void updateProxyConfig() throws Exception {
private void updateProxyConfig() {
if (ModelUtil.hasLength(Default.getString(Default.PROXY_PORT)) && ModelUtil.hasLength(Default.getString(Default.PROXY_HOST))) {
String port = Default.getString(Default.PROXY_PORT);
String host = Default.getString(Default.PROXY_HOST);

View File

@ -314,7 +314,7 @@ public final class MainWindow extends ChatFrame implements ActionListener {
}
}
private File getLibDirectory() throws IOException {
private File getLibDirectory() {
File jarFile;
try{
jarFile = new File(Startup.class.getProtectionDomain().getCodeSource().getLocation().toURI());

View File

@ -41,7 +41,7 @@ public class Installer implements InstallAction {
}
@Override
public boolean install(InstallerContext installerContext) throws UserCanceledException {
public boolean install(InstallerContext installerContext) {
final String osName = System.getProperty("os.name").toLowerCase();
boolean isWindows = osName.startsWith("windows");

View File

@ -159,7 +159,7 @@ public class FileDragLabel extends JLabel implements DropTargetListener, DragSou
@NotNull
@Override
public synchronized Object getTransferData(DataFlavor flavor)
throws UnsupportedFlavorException, IOException {
throws UnsupportedFlavorException {
if (flavor.equals(flavors[FILE])) {
return this;
}

View File

@ -227,7 +227,7 @@ public class JiveTreeNode extends DefaultMutableTreeNode implements Transferable
@NotNull
@Override
public Object getTransferData(DataFlavor flavor)
throws UnsupportedFlavorException, IOException {
throws UnsupportedFlavorException {
if (this.isDataFlavorSupported(flavor)) {
return this;
}

View File

@ -510,8 +510,7 @@ public class SparkTabbedPane extends JPanel {
private final DataFlavor FLAVOR = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType, NAME);
@NotNull
@Override
public Object getTransferData(DataFlavor flavor)
throws UnsupportedFlavorException, IOException {
public Object getTransferData(DataFlavor flavor) {
return pane;
}

View File

@ -162,7 +162,7 @@ public class ContactGroupTransferHandler extends TransferHandler {
// Returns image
@NotNull
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
if (!DataFlavor.imageFlavor.equals(flavor)) {
throw new UnsupportedFlavorException(flavor);
}

View File

@ -310,9 +310,8 @@ public class ContactList extends JPanel implements ActionListener,
* Updates the users presence.
*
* @param presence the user to update.
* @throws Exception if there is a problem while updating the user's presence.
*/
private synchronized void updateUserPresence(Presence presence) throws Exception {
private synchronized void updateUserPresence(Presence presence) {
if (presence.getError() != null) {
// We ignore this.
return;

View File

@ -72,7 +72,7 @@ public class RoomCreationDialog extends JPanel {
}
}
private void jbInit() throws Exception {
private void jbInit() {
this.setLayout(gridBagLayout1);
this.add(confirmPasswordField, new GridBagConstraints(1, 4, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
this.add(passwordField, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));

View File

@ -381,7 +381,7 @@ public class CertificateDialog extends JDialog implements ActionListener {
try {
certControll.deleteEntry(certModel.getAlias());
this.dispose();
} catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException ex) {
} catch (KeyStoreException ex) {
Log.error("Couldn't delete the certificate", ex);
}
@ -397,8 +397,8 @@ public class CertificateDialog extends JDialog implements ActionListener {
certStatusArea.setText(certModel.getCertStatusAll());
try {
certControll.addCertificateToBlackList(certModel.getCertificate());
} catch (HeadlessException | KeyStoreException | NoSuchAlgorithmException | CertificateException
| InvalidNameException | IOException ex) {
} catch (HeadlessException | KeyStoreException
| InvalidNameException ex) {
Log.warning("Couldn't add certificate to the blacklist", ex);
}
certStatusArea.updateUI();

View File

@ -142,10 +142,8 @@ class SsoLoginSettingsPanel extends JPanel implements ActionListener
* Returns the principal name if one exists.
*
* @return the name (ex. derek) of the principal.
* @throws Exception thrown if a Principal was not found.
*/
private String getPrincipalName() throws Exception
{
private String getPrincipalName() {
if ( localPreferences.getDebug() )
{
System.setProperty( "java.security.krb5.debug", "true" );

View File

@ -101,10 +101,8 @@ public class UriManager {
*
* @param uri
* the decoded uri
* @throws Exception
* thrown if the conference cannot be joined.
*/
public void handleConference(URI uri) throws Exception {
public void handleConference(URI uri) {
Jid jid = retrieveJID(uri);
ConferenceUtils.joinConferenceOnSeperateThread(jid, jid.asEntityBareJidOrThrow(), null);
}

View File

@ -61,13 +61,13 @@ public class Encryptor {
try {
return decryptOrThrow(string);
}
catch (IllegalBlockSizeException | BadPaddingException | UnsupportedEncodingException e) {
catch (IllegalBlockSizeException | BadPaddingException e) {
Log.error(e);
return null;
}
}
public static String decryptOrThrow(String string) throws UnsupportedEncodingException, BadPaddingException, IllegalBlockSizeException {
public static String decryptOrThrow(String string) throws BadPaddingException, IllegalBlockSizeException {
byte[] dec = Base64.decode( string );
// Decrypt
@ -77,7 +77,7 @@ public class Encryptor {
return new String(utf8, StandardCharsets.UTF_8);
}
private static SecretKey decodeKey() throws Exception {
private static SecretKey decodeKey() {
String secretKey = "ugfpV1dMC5jyJtqwVAfTpHkxqJ0+E0ae";
byte[] bytes = Base64.decode( secretKey );
return new SecretKeySpec(bytes, "DESede");

View File

@ -655,18 +655,16 @@ public final class GraphicUtils {
*
* @param im
* @return {@link BufferedImage}
* @throws InterruptedException
* @throws {@link IOException}
*/
public static BufferedImage convert(Image im) throws InterruptedException,
IOException {
//load(im);
BufferedImage bi = new BufferedImage(im.getWidth(null),
im.getHeight(null), BufferedImage.TYPE_INT_ARGB_PRE);
Graphics bg = bi.getGraphics();
bg.drawImage(im, 0, 0, null);
bg.dispose();
return bi;
public static BufferedImage convert(Image im) {
//load(im);
BufferedImage bi = new BufferedImage(im.getWidth(null),
im.getHeight(null), BufferedImage.TYPE_INT_ARGB_PRE);
Graphics bg = bi.getGraphics();
bg.drawImage(im, 0, 0, null);
bg.dispose();
return bi;
}
/**

View File

@ -59,11 +59,10 @@ public class WindowsFileSystemView extends FileSystemView {
* createNewFolder
*
* @param value0
* @throws IOException
* @return File
*/
@Override
public File createNewFolder(File value0) throws IOException {
public File createNewFolder(File value0) {
return null; //
} // createNewFolder()

View File

@ -61,7 +61,7 @@ public abstract class CertManager {
protected final List<CertificateModel> blackListedCertificates = new LinkedList<>(); //contain only revoked certificates
protected DefaultTableModel tableModel;
public abstract void deleteEntry(String alias) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException;
public abstract void deleteEntry(String alias) throws KeyStoreException;
public abstract void addOrRemoveFromExceptionList(boolean checked);
public abstract boolean isOnExceptionList(CertificateModel cert);
@ -69,8 +69,8 @@ public abstract class CertManager {
protected abstract void refreshCertTable();
public abstract void addEntryFileToKeyStore(File file)
throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException, HeadlessException,
InvalidNameException, UnrecoverableKeyException, InvalidKeySpecException;
throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException, HeadlessException,
InvalidNameException, InvalidKeySpecException;
/**
* Check if there is certificate entry in KeyStore with the same alias.
* @param alias which is checked if it already exist in keystore
@ -100,7 +100,7 @@ public abstract class CertManager {
* @param addedCert the certificate for which it method look in the model list
* @return true if KeyStore already have this certificate.
*/
protected boolean checkForSameCertificate(X509Certificate addedCert) throws KeyStoreException{
protected boolean checkForSameCertificate(X509Certificate addedCert) {
// check if this certificate isn't already added to Truststore
for(CertificateModel model :allCertificates){
X509Certificate certificateCheck = model.getCertificate();
@ -132,7 +132,7 @@ public abstract class CertManager {
}
}
} catch (CRLException | CertificateException | IOException | InvalidAlgorithmParameterException
| NoSuchAlgorithmException | CertStoreException e) {
| NoSuchAlgorithmException e) {
Log.warning("Cannot check validity", e);
}
return revoked;
@ -146,8 +146,8 @@ public abstract class CertManager {
* @throws InvalidNameException
* @throws HeadlessException
*/
public void addCertificateToBlackList(X509Certificate cert) throws KeyStoreException, NoSuchAlgorithmException,
CertificateException, IOException, HeadlessException, InvalidNameException {
public void addCertificateToBlackList(X509Certificate cert) throws KeyStoreException,
HeadlessException, InvalidNameException {
blackListStore.setCertificateEntry(useCommonNameAsAlias(cert), cert);
blackListedCertificates.add(new CertificateModel(cert));
}

View File

@ -399,10 +399,7 @@ public class CertificateController extends CertManager {
*
* @param alias Alias of the certificate to delete
* @throws KeyStoreException
* @throws IOException
* @throws NoSuchAlgorithmException
* @throws CertificateException
*/
*/
@Override
public void deleteEntry(String alias) throws KeyStoreException {
int dialogButton = JOptionPane.YES_NO_OPTION;
@ -603,10 +600,9 @@ public class CertificateController extends CertManager {
* @param alias Alias of the certificate which is looked for in the model list
* @return True if KeyStore contain the same alias.
* @throws HeadlessException
* @throws KeyStoreException
*/
*/
@Override
protected boolean checkForSameAlias(String alias) throws HeadlessException, KeyStoreException {
protected boolean checkForSameAlias(String alias) throws HeadlessException {
for(CertificateModel model: allCertificates){
if(model.getAlias().equals(alias)){
return true;

View File

@ -264,7 +264,7 @@ public class CertificateModel {
return value;
}
private String alternativeNameExtractor(Collection<List<?>> rootNames) throws CertificateParsingException {
private String alternativeNameExtractor(Collection<List<?>> rootNames) {
StringBuilder value = new StringBuilder();
if (rootNames != null) {
for (List<?> names : rootNames) {

View File

@ -147,11 +147,9 @@ public class IdentityController extends CertManager {
/**
* Creates Certificate Signing Request.
*
* @throws IOException
* @throws OperatorCreationException
*/
public PKCS10CertificationRequest createCSR(KeyPair keyPair) throws IOException, OperatorCreationException {
public PKCS10CertificationRequest createCSR(KeyPair keyPair) throws OperatorCreationException {
X500Principal principal = new X500Principal(createX500NameString());
PKCS10CertificationRequestBuilder p10Builder = new JcaPKCS10CertificationRequestBuilder(principal, keyPair.getPublic());
@ -243,7 +241,6 @@ public class IdentityController extends CertManager {
* @throws KeyStoreException
* @throws NoSuchAlgorithmException
* @throws CertificateException
* @throws UnrecoverableKeyException
* @throws InvalidKeySpecException
* @throws HeadlessException
* @throws InvalidNameException
@ -296,7 +293,7 @@ public class IdentityController extends CertManager {
return idStore.containsAlias(alias);
}
public KeyPair createKeyPair() throws NoSuchAlgorithmException, NoSuchProviderException, FileNotFoundException, IOException {
public KeyPair createKeyPair() throws NoSuchAlgorithmException, NoSuchProviderException {
KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA", "BC" );
generator.initialize(2048, new SecureRandom());
keyPair = generator.generateKeyPair();
@ -304,7 +301,7 @@ public class IdentityController extends CertManager {
return keyPair;
}
public X509Certificate createSelfSignedCertificate(KeyPair keyPair) throws NoSuchAlgorithmException, NoSuchProviderException, CertIOException, OperatorCreationException, CertificateException {
public X509Certificate createSelfSignedCertificate(KeyPair keyPair) throws CertIOException, OperatorCreationException, CertificateException {
long serial = System.currentTimeMillis();
SubjectPublicKeyInfo keyInfo = SubjectPublicKeyInfo.getInstance(keyPair.getPublic().getEncoded());

View File

@ -127,7 +127,6 @@ public class PemHelper {
public static void saveToPemFile(Object object, File file) throws FileNotFoundException, IOException{
try (JcaPEMWriter pem = new JcaPEMWriter(new OutputStreamWriter(new FileOutputStream(file)))) {
pem.writeObject(object);
pem.close();
}
}
@ -143,12 +142,11 @@ public class PemHelper {
buildList.add(object);
}
public void saveToPemFile(File file) throws FileNotFoundException, IOException {
public void saveToPemFile(File file) throws IOException {
try (JcaPEMWriter pem = new JcaPEMWriter(new OutputStreamWriter(new FileOutputStream(file)))) {
for (Object object : buildList) {
pem.writeObject(object);
}
pem.close();
}
}
}

View File

@ -31,7 +31,7 @@ public class SparkExceptionsTrustManager extends GeneralTrustManager implements
}
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
public void checkClientTrusted(X509Certificate[] chain, String authType) {
throw new UnsupportedOperationException("This implementation cannot be used to validate client-provided certificate chains.");
}

View File

@ -73,7 +73,7 @@ public class SparkTrustManager extends GeneralTrustManager implements X509TrustM
}
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
public void checkClientTrusted(X509Certificate[] chain, String authType) {
throw new UnsupportedOperationException("This implementation cannot be used to validate client-provided certificate chains.");
}
@ -145,8 +145,7 @@ public class SparkTrustManager extends GeneralTrustManager implements X509TrustM
throw new CertificateException("Certificate is revoked");
}
}
} catch (InvalidAlgorithmParameterException | NoSuchAlgorithmException | CertStoreException
| CRLException | IOException e) {
} catch (InvalidAlgorithmParameterException | NoSuchAlgorithmException | CRLException | IOException e) {
Log.warning("Couldn't load CRL");
}
} else {
@ -404,7 +403,7 @@ public class SparkTrustManager extends GeneralTrustManager implements X509TrustM
public Collection<X509CRL> loadCRL(X509Certificate[] chain) throws IOException, InvalidAlgorithmParameterException,
NoSuchAlgorithmException, CertStoreException, CRLException, CertificateException {
NoSuchAlgorithmException, CRLException {
// for each certificate in chain
for (X509Certificate cert : chain) {

View File

@ -57,8 +57,7 @@ public class BuzzPacket implements ExtensionElement
}
@Override
public BuzzPacket parse( XmlPullParser parser, int i ) throws XmlPullParserException, IOException, SmackException
{
public BuzzPacket parse( XmlPullParser parser, int i ) {
return new BuzzPacket();
}
}

View File

@ -126,7 +126,7 @@ public class GatewayPlugin implements Plugin, ContactItemHandler {
public void uninstall() {
}
private void populateTransports() throws Exception {
private void populateTransports() {
DiscoverItems discoItems = SparkManager.getSessionManager().getDiscoveredItems();
for (DiscoverItems.Item item : discoItems.getItems() ) {

View File

@ -278,8 +278,7 @@ public class SparkPrivacyList {
/**
* @param item user was added into blockList
*/
private void fireItemAdded( PrivacyItem item ) throws SmackException.NotConnectedException
{
private void fireItemAdded( PrivacyItem item ) {
for ( final SparkPrivacyItemListener listener : _listeners )
{
try
@ -296,8 +295,7 @@ public class SparkPrivacyList {
/**
* @param item user removed from blackList
*/
private void fireItemRemoved( PrivacyItem item ) throws SmackException.NotConnectedException
{
private void fireItemRemoved( PrivacyItem item ) {
for ( final SparkPrivacyItemListener listener : _listeners )
{
try

View File

@ -59,8 +59,7 @@ public class JabberAvatarExtension implements ExtensionElement {
}
@Override
public JabberAvatarExtension parse( XmlPullParser parser, int i ) throws XmlPullParserException, IOException, SmackException
{
public JabberAvatarExtension parse( XmlPullParser parser, int i ) throws XmlPullParserException, IOException {
final JabberAvatarExtension result = new JabberAvatarExtension();
while ( true )

View File

@ -65,8 +65,7 @@ public class VCardUpdateExtension implements ExtensionElement {
}
@Override
public VCardUpdateExtension parse( XmlPullParser parser, int i ) throws XmlPullParserException, IOException, SmackException
{
public VCardUpdateExtension parse( XmlPullParser parser, int i ) throws XmlPullParserException, IOException {
final VCardUpdateExtension result = new VCardUpdateExtension();
while ( true )

View File

@ -131,9 +131,8 @@ public class UserSearchService implements Searchable {
* Returns a collection of search services found on the server.
*
* @return a Collection of search services found on the server.
* @throws XMPPException thrown if a server error has occurred.
*/
private Collection<DomainBareJid> getServices() throws Exception {
private Collection<DomainBareJid> getServices() {
final Set<DomainBareJid> searchServices = new HashSet<>();
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection());
DiscoverItems items = SparkManager.getSessionManager().getDiscoveredItems();

View File

@ -359,9 +359,8 @@ public class CheckUpdates {
* Checks Spark Manager and/or Jive Software for the latest version of Spark.
*
* @param explicit true if the user explicitly asks for the latest version.
* @throws Exception if there is an error during check
*/
public void checkForUpdate(boolean explicit) throws Exception {
public void checkForUpdate(boolean explicit) {
if (UPDATING) {
return;
}

View File

@ -108,11 +108,11 @@ public class EasyX509TrustManager implements X509TrustManager {
}
@Override
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) {
}
@Override
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) {
}
/**

View File

@ -8,8 +8,7 @@ import static org.junit.Assert.assertEquals;
public class JavaVersionTest
{
@Test
public void testJava7() throws Exception
{
public void testJava7() {
// Setup fixture.
final String value = "1.7.0";
@ -22,8 +21,7 @@ public class JavaVersionTest
@Test
public void testJava9() throws Exception
{
public void testJava9() {
// Setup fixture.
final String value = "9.0.0.15";
@ -35,8 +33,7 @@ public class JavaVersionTest
}
@Test
public void testJava11() throws Exception
{
public void testJava11() {
// Setup fixture.
final String value = "11.0.1";

View File

@ -30,7 +30,7 @@ public class AppleTest implements ActionListener {
new AppleTest();
}
public AppleTest() throws InterruptedException {
public AppleTest() {
for (LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
System.out.println(laf.getClassName() + " " + laf.getName());

View File

@ -106,7 +106,7 @@ public class FlashWindow {
}
}
public static void main(String[] args) throws Exception {
public static void main(String[] args) {
final JFrame frame = new JFrame();
frame.setTitle("Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

View File

@ -65,7 +65,7 @@ public class StreamReader {
}
private void stopReader() throws IOException {
private void stopReader() {
//stream.close();
stopped = true;
listener.onClosed();

View File

@ -264,10 +264,9 @@ public class RoarProperties {
* @param s
* @return
*/
public static Color convertString(String s) throws Exception {
public static Color convertString(String s) {
String[] arr = s.split(",");
return new Color(Integer.parseInt(arr[0]), Integer.parseInt(arr[1]), Integer.parseInt(arr[2]));
}
/**