Skip to content

Commit dbd22ec

Browse files
jmehrenslukasj
authored andcommitted
Remove this-escape compiler warnings #141 (#142)
Signed-off-by: jmehrens jason_mehrens@hotmail.com
1 parent a53d904 commit dbd22ec

File tree

37 files changed

+172
-84
lines changed

37 files changed

+172
-84
lines changed

core/src/main/java/org/eclipse/angus/mail/util/MailConnectException.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2024 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -30,17 +30,19 @@
3030
*/
3131

3232
public class MailConnectException extends MessagingException {
33-
private String host;
34-
private int port;
35-
private int cto;
33+
private final String host;
34+
private final int port;
35+
private final int cto;
3636

3737
private static final long serialVersionUID = -3818807731125317729L;
3838

3939
/**
4040
* Constructs a MailConnectException.
4141
*
4242
* @param cex the SocketConnectException with the details
43+
* @throws NullPointerException if given exception is {@code null}.
4344
*/
45+
@SuppressWarnings("this-escape")
4446
public MailConnectException(SocketConnectException cex) {
4547
super(
4648
"Couldn't connect to host, port: " +
@@ -51,7 +53,7 @@ public MailConnectException(SocketConnectException cex) {
5153
this.host = cex.getHost();
5254
this.port = cex.getPort();
5355
this.cto = cex.getConnectionTimeout();
54-
setNextException(cex.getException());
56+
super.setNextException(cex.getException());
5557
}
5658

5759
/**

core/src/main/java/org/eclipse/angus/mail/util/SocketConnectException.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2024 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -32,15 +32,15 @@ public class SocketConnectException extends IOException {
3232
/**
3333
* The socket host name.
3434
*/
35-
private String host;
35+
private final String host;
3636
/**
3737
* The socket port.
3838
*/
39-
private int port;
39+
private final int port;
4040
/**
4141
* The connection timeout.
4242
*/
43-
private int cto;
43+
private final int cto;
4444
/**
4545
* The generated serial id.
4646
*/
@@ -57,8 +57,7 @@ public class SocketConnectException extends IOException {
5757
*/
5858
public SocketConnectException(String msg, Exception cause,
5959
String host, int port, int cto) {
60-
super(msg);
61-
initCause(cause);
60+
super(msg, cause);
6261
this.host = host;
6362
this.port = port;
6463
this.cto = cto;
@@ -71,8 +70,8 @@ public SocketConnectException(String msg, Exception cause,
7170
*/
7271
public Exception getException() {
7372
// the "cause" is always an Exception; see constructor above
74-
Throwable t = getCause();
75-
assert t == null || t instanceof Exception;
73+
Throwable t = super.getCause();
74+
assert t == null || t instanceof Exception : t;
7675
return (Exception) t;
7776
}
7877

demos/client/src/main/java/example/client/ComponentFrame.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2024 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Distribution License v. 1.0, which is available at
@@ -20,6 +20,7 @@
2020
* @author Christopher Cotton
2121
*/
2222
public class ComponentFrame extends JFrame {
23+
private static final long serialVersionUID = -1L;
2324

2425
/**
2526
* creates the frame
@@ -36,6 +37,7 @@ public ComponentFrame(Component what) {
3637
* @param what the component to display
3738
* @param name the name of the Frame
3839
*/
40+
@SuppressWarnings("this-escape")
3941
public ComponentFrame(Component what, String name) {
4042
super(name);
4143

demos/client/src/main/java/example/client/FolderModel.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2024 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Distribution License v. 1.0, which is available at
@@ -25,12 +25,12 @@
2525
* @author Bill Shannon
2626
*/
2727
public class FolderModel extends AbstractTableModel {
28-
28+
private static final long serialVersionUID = -1L;
2929
Folder folder;
3030
Message[] messages;
3131

3232
String[] columnNames = {"Date", "From", "Subject"};
33-
Class[] columnTypes = {String.class, String.class, String.class};
33+
Class<?>[] columnTypes = {String.class, String.class, String.class};
3434

3535
public void setFolder(Folder what) throws MessagingException {
3636
if (what != null) {
@@ -62,26 +62,31 @@ public Message getMessage(int which) {
6262
// Implementation of the TableModel methods
6363
//---------------------
6464

65+
@Override
6566
public String getColumnName(int column) {
6667
return columnNames[column];
6768
}
6869

69-
public Class getColumnClass(int column) {
70+
@Override
71+
public Class<?> getColumnClass(int column) {
7072
return columnTypes[column];
7173
}
7274

7375

76+
@Override
7477
public int getColumnCount() {
7578
return columnNames.length;
7679
}
7780

81+
@Override
7882
public int getRowCount() {
7983
if (messages == null)
8084
return 0;
8185

8286
return messages.length;
8387
}
8488

89+
@Override
8590
public Object getValueAt(int aRow, int aColumn) {
8691
switch (aColumn) {
8792
case 0: // date

demos/client/src/main/java/example/client/FolderTreeNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2024 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Distribution License v. 1.0, which is available at
@@ -21,7 +21,7 @@
2121
* @author Christopher Cotton
2222
*/
2323
public class FolderTreeNode extends DefaultMutableTreeNode {
24-
24+
private static final long serialVersionUID = -1L;
2525
protected Folder folder = null;
2626
protected boolean hasLoaded = false;
2727

demos/client/src/main/java/example/client/FolderViewer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2024 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Distribution License v. 1.0, which is available at
@@ -24,6 +24,7 @@
2424
* @author Bill Shannon
2525
*/
2626
public class FolderViewer extends JPanel {
27+
private static final long serialVersionUID = -1L;
2728

2829
FolderModel model = new FolderModel();
2930
JScrollPane scrollpane;
@@ -33,6 +34,7 @@ public FolderViewer() {
3334
this(null);
3435
}
3536

37+
@SuppressWarnings("this-escape")
3638
public FolderViewer(Folder what) {
3739
super(new GridLayout(1, 1));
3840

demos/client/src/main/java/example/client/MessageViewer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2024 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Distribution License v. 1.0, which is available at
@@ -32,6 +32,7 @@
3232
* @author Bill Shannon
3333
*/
3434
public class MessageViewer extends JPanel implements CommandObject {
35+
private static final long serialVersionUID = -1L;
3536

3637
Message displayed = null;
3738
DataHandler dataHandler = null;
@@ -43,6 +44,7 @@ public MessageViewer() {
4344
this(null);
4445
}
4546

47+
@SuppressWarnings("this-escape")
4648
public MessageViewer(Message what) {
4749
// set our layout
4850
super(new GridBagLayout());

demos/client/src/main/java/example/client/MultipartViewer.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2024 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Distribution License v. 1.0, which is available at
@@ -29,7 +29,7 @@
2929
* @author Christopher Cotton
3030
*/
3131
public class MultipartViewer extends JPanel implements CommandObject {
32-
32+
private static final long serialVersionUID = -1L;
3333
protected DataHandler dh = null;
3434
protected String verb = null;
3535

@@ -38,6 +38,7 @@ public MultipartViewer() {
3838
}
3939

4040

41+
@Override
4142
public void setCommandContext(String verb, DataHandler dh) throws IOException {
4243
this.verb = verb;
4344
this.dh = dh;
@@ -157,11 +158,12 @@ public AttachmentViewer(BodyPart part) {
157158
bp = part;
158159
}
159160

161+
@Override
160162
public void actionPerformed(ActionEvent e) {
161163
ComponentFrame f = new ComponentFrame(
162164
getComponent(bp), "Attachment");
163165
f.pack();
164-
f.show();
166+
f.setVisible(true);
165167
}
166168
}
167169

demos/client/src/main/java/example/client/SimpleAuthenticator.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2024 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Distribution License v. 1.0, which is available at
@@ -116,10 +116,11 @@ protected PasswordAuthentication getPasswordAuthentication() {
116116
int result = JOptionPane.showConfirmDialog(frame, d, "Login",
117117
JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
118118

119-
if (result == JOptionPane.OK_OPTION)
119+
if (result == JOptionPane.OK_OPTION) {
120+
char[] pw = password.getPassword();
120121
return new PasswordAuthentication(username.getText(),
121-
password.getText());
122-
else
122+
pw == null ? (String) null : new String(pw));
123+
} else
123124
return null;
124125
}
125126

demos/client/src/main/java/example/client/SimpleClient.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2024 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Distribution License v. 1.0, which is available at
@@ -41,7 +41,7 @@
4141

4242
public class SimpleClient {
4343

44-
static Vector url = new Vector();
44+
static Vector<String> url = new Vector<>();
4545
static FolderViewer fv;
4646
static MessageViewer mv;
4747

@@ -60,7 +60,7 @@ public static void main(String[] argv) {
6060
}
6161
}
6262

63-
if (usage || url.size() == 0) {
63+
if (usage || url.isEmpty()) {
6464
System.out.println("Usage: client.SimpleClient -L url");
6565
System.out.println(" where url is protocol://username:password@hostname/");
6666
System.exit(1);
@@ -81,6 +81,7 @@ public static void main(String[] argv) {
8181

8282
JFrame frame = new JFrame("Simple Jakarta Mail Client");
8383
frame.addWindowListener(new WindowAdapter() {
84+
@Override
8485
public void windowClosing(WindowEvent e) {
8586
System.exit(0);
8687
}
@@ -96,8 +97,8 @@ public void windowClosing(WindowEvent e) {
9697
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
9798

9899
// create a node for each store we have
99-
for (Enumeration e = url.elements(); e.hasMoreElements(); ) {
100-
String urlstring = (String) e.nextElement();
100+
for (Enumeration<String> e = url.elements(); e.hasMoreElements(); ) {
101+
String urlstring = e.nextElement();
101102
URLName urln = new URLName(urlstring);
102103
Store store = session.getStore(urln);
103104

@@ -130,7 +131,7 @@ public void windowClosing(WindowEvent e) {
130131

131132
frame.getContentPane().add(jsp2);
132133
frame.pack();
133-
frame.show();
134+
frame.setVisible(true);
134135

135136
} catch (Exception ex) {
136137
System.out.println("SimpletClient caught exception");
@@ -143,6 +144,7 @@ public void windowClosing(WindowEvent e) {
143144

144145
class TreePress implements TreeSelectionListener {
145146

147+
@Override
146148
public void valueChanged(TreeSelectionEvent e) {
147149
TreePath path = e.getNewLeadSelectionPath();
148150
if (path != null) {

0 commit comments

Comments
 (0)