Skip to content

Commit

Permalink
Remove this-escape compiler warnings #141 (#142)
Browse files Browse the repository at this point in the history
Signed-off-by: jmehrens jason_mehrens@hotmail.com
  • Loading branch information
jmehrens authored Mar 7, 2024
1 parent 80c6726 commit c959e02
Show file tree
Hide file tree
Showing 37 changed files with 177 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -30,17 +30,19 @@
*/

public class MailConnectException extends MessagingException {
private String host;
private int port;
private int cto;
private final String host;
private final int port;
private final int cto;

private static final long serialVersionUID = -3818807731125317729L;

/**
* Constructs a MailConnectException.
*
* @param cex the SocketConnectException with the details
* @throws NullPointerException if given exception is {@code null}.
*/
@SuppressWarnings("this-escape")
public MailConnectException(SocketConnectException cex) {
super(
"Couldn't connect to host, port: " +
Expand All @@ -51,7 +53,7 @@ public MailConnectException(SocketConnectException cex) {
this.host = cex.getHost();
this.port = cex.getPort();
this.cto = cex.getConnectionTimeout();
setNextException(cex.getException());
super.setNextException(cex.getException());
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -32,15 +32,15 @@ public class SocketConnectException extends IOException {
/**
* The socket host name.
*/
private String host;
private final String host;
/**
* The socket port.
*/
private int port;
private final int port;
/**
* The connection timeout.
*/
private int cto;
private final int cto;
/**
* The generated serial id.
*/
Expand All @@ -57,8 +57,7 @@ public class SocketConnectException extends IOException {
*/
public SocketConnectException(String msg, Exception cause,
String host, int port, int cto) {
super(msg);
initCause(cause);
super(msg, cause);
this.host = host;
this.port = port;
this.cto = cto;
Expand All @@ -71,8 +70,8 @@ public SocketConnectException(String msg, Exception cause,
*/
public Exception getException() {
// the "cause" is always an Exception; see constructor above
Throwable t = getCause();
assert t == null || t instanceof Exception;
Throwable t = super.getCause();
assert t == null || t instanceof Exception : t;
return (Exception) t;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand All @@ -20,6 +20,7 @@
* @author Christopher Cotton
*/
public class ComponentFrame extends JFrame {
private static final long serialVersionUID = -1L;

/**
* creates the frame
Expand All @@ -36,6 +37,7 @@ public ComponentFrame(Component what) {
* @param what the component to display
* @param name the name of the Frame
*/
@SuppressWarnings("this-escape")
public ComponentFrame(Component what, String name) {
super(name);

Expand Down
13 changes: 9 additions & 4 deletions demos/client/src/main/java/example/client/FolderModel.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand All @@ -25,12 +25,12 @@
* @author Bill Shannon
*/
public class FolderModel extends AbstractTableModel {

private static final long serialVersionUID = -1L;
Folder folder;
Message[] messages;

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

public void setFolder(Folder what) throws MessagingException {
if (what != null) {
Expand Down Expand Up @@ -62,26 +62,31 @@ public Message getMessage(int which) {
// Implementation of the TableModel methods
//---------------------

@Override
public String getColumnName(int column) {
return columnNames[column];
}

public Class getColumnClass(int column) {
@Override
public Class<?> getColumnClass(int column) {
return columnTypes[column];
}


@Override
public int getColumnCount() {
return columnNames.length;
}

@Override
public int getRowCount() {
if (messages == null)
return 0;

return messages.length;
}

@Override
public Object getValueAt(int aRow, int aColumn) {
switch (aColumn) {
case 0: // date
Expand Down
4 changes: 2 additions & 2 deletions demos/client/src/main/java/example/client/FolderTreeNode.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand All @@ -21,7 +21,7 @@
* @author Christopher Cotton
*/
public class FolderTreeNode extends DefaultMutableTreeNode {

private static final long serialVersionUID = -1L;
protected Folder folder = null;
protected boolean hasLoaded = false;

Expand Down
4 changes: 3 additions & 1 deletion demos/client/src/main/java/example/client/FolderViewer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand All @@ -24,6 +24,7 @@
* @author Bill Shannon
*/
public class FolderViewer extends JPanel {
private static final long serialVersionUID = -1L;

FolderModel model = new FolderModel();
JScrollPane scrollpane;
Expand All @@ -33,6 +34,7 @@ public FolderViewer() {
this(null);
}

@SuppressWarnings("this-escape")
public FolderViewer(Folder what) {
super(new GridLayout(1, 1));

Expand Down
4 changes: 3 additions & 1 deletion demos/client/src/main/java/example/client/MessageViewer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -32,6 +32,7 @@
* @author Bill Shannon
*/
public class MessageViewer extends JPanel implements CommandObject {
private static final long serialVersionUID = -1L;

Message displayed = null;
DataHandler dataHandler = null;
Expand All @@ -43,6 +44,7 @@ public MessageViewer() {
this(null);
}

@SuppressWarnings("this-escape")
public MessageViewer(Message what) {
// set our layout
super(new GridBagLayout());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -29,7 +29,7 @@
* @author Christopher Cotton
*/
public class MultipartViewer extends JPanel implements CommandObject {

private static final long serialVersionUID = -1L;
protected DataHandler dh = null;
protected String verb = null;

Expand All @@ -38,6 +38,7 @@ public MultipartViewer() {
}


@Override
public void setCommandContext(String verb, DataHandler dh) throws IOException {
this.verb = verb;
this.dh = dh;
Expand Down Expand Up @@ -157,11 +158,12 @@ public AttachmentViewer(BodyPart part) {
bp = part;
}

@Override
public void actionPerformed(ActionEvent e) {
ComponentFrame f = new ComponentFrame(
getComponent(bp), "Attachment");
f.pack();
f.show();
f.setVisible(true);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -116,10 +116,11 @@ protected PasswordAuthentication getPasswordAuthentication() {
int result = JOptionPane.showConfirmDialog(frame, d, "Login",
JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);

if (result == JOptionPane.OK_OPTION)
if (result == JOptionPane.OK_OPTION) {
char[] pw = password.getPassword();
return new PasswordAuthentication(username.getText(),
password.getText());
else
pw == null ? (String) null : new String(pw));
} else
return null;
}

Expand Down
14 changes: 8 additions & 6 deletions demos/client/src/main/java/example/client/SimpleClient.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -41,7 +41,7 @@

public class SimpleClient {

static Vector url = new Vector();
static Vector<String> url = new Vector<>();
static FolderViewer fv;
static MessageViewer mv;

Expand All @@ -60,7 +60,7 @@ public static void main(String[] argv) {
}
}

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

JFrame frame = new JFrame("Simple Jakarta Mail Client");
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
Expand All @@ -96,8 +97,8 @@ public void windowClosing(WindowEvent e) {
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");

// create a node for each store we have
for (Enumeration e = url.elements(); e.hasMoreElements(); ) {
String urlstring = (String) e.nextElement();
for (Enumeration<String> e = url.elements(); e.hasMoreElements(); ) {
String urlstring = e.nextElement();
URLName urln = new URLName(urlstring);
Store store = session.getStore(urln);

Expand Down Expand Up @@ -130,7 +131,7 @@ public void windowClosing(WindowEvent e) {

frame.getContentPane().add(jsp2);
frame.pack();
frame.show();
frame.setVisible(true);

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

class TreePress implements TreeSelectionListener {

@Override
public void valueChanged(TreeSelectionEvent e) {
TreePath path = e.getNewLeadSelectionPath();
if (path != null) {
Expand Down
4 changes: 2 additions & 2 deletions demos/client/src/main/java/example/client/StoreTreeNode.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand All @@ -23,7 +23,7 @@
* @author Christopher Cotton
*/
public class StoreTreeNode extends DefaultMutableTreeNode {

private static final long serialVersionUID = -1L;
protected Store store = null;
protected Folder folder = null;
protected String display = null;
Expand Down
4 changes: 3 additions & 1 deletion demos/client/src/main/java/example/client/TextViewer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand All @@ -26,13 +26,15 @@
*/
public class TextViewer extends JPanel implements CommandObject {

private static final long serialVersionUID = -1L;
private JTextArea text_area = null;
private DataHandler dh = null;
private String verb = null;

/**
* Constructor
*/
@SuppressWarnings("this-escape")
public TextViewer() {
super(new GridLayout(1, 1));

Expand Down
Loading

0 comments on commit c959e02

Please sign in to comment.