try { if (loginMethod == AuthenticationManager.LOGIN) { protocol.login(item.get("user"), password); // If no exception happened we have successfully logged // in authenticated = true; } else { try { // AUTH protocol.authenticate(AuthenticationManager .getSaslName(loginMethod), item.get("user"), password); // If no exception happened we have successfully logged // in authenticated = true; } catch (AuthenticationException e) { // If the cause is a IMAPExcpetion then only password // wrong // else bogus authentication mechanism if (e.getCause() instanceof IMAPException) throw (IMAPException) e.getCause(); // Some error in the client/server communication // --> fall back to default login process int result = JOptionPane .showConfirmDialog( FrameManager.getInstance() .getActiveFrame(), new MultiLineLabel( e.getMessage() + "\n" + MailResourceLoader .getString( "dialog", "error", "authentication_fallback_to_default")), MailResourceLoader.getString("dialog", "error", "authentication_process_error"), JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.OK_OPTION) { loginMethod = AuthenticationManager.LOGIN; item.setString("login_method", Integer .toString(loginMethod)); } else { throw new CommandCancelledException(); } } } } catch (IMAPException ex) { // login failed? IMAPResponse response = ex.getResponse(); if (response == null || !response.isNO()) { // This exception is not because wrong username or // password throw ex; } }
if (loginMethod == AuthenticationManager.APOP) { try { protocol.apop(popItem.get("user"), password); } catch (POP3Exception e1) { // some server have a bogus apop // try user/pass to check if the password is // correct protocol.userPass(popItem.get("user"), password); LOG .warning(popItem.get("host") + " : bogus APOP implementation -> falling back to USER/PASS."); // user/pass worked -> this is indeed // a bogus server. } login = true; } else { try { // AUTH protocol.auth(AuthenticationManager .getSaslName(loginMethod), popItem.get("user"), password); login = true; } catch (AuthenticationException e) { // If the cause is a IMAPExcpetion then only password // wrong // else bogus authentication mechanism if (e.getCause() instanceof POP3Exception) throw (POP3Exception) e.getCause(); // Some error in the client/server communication // --> fall back to default login process int result = JOptionPane .showConfirmDialog( FrameManager.getInstance() .getActiveFrame(), new MultiLineLabel( e.getMessage() + "\n" + MailResourceLoader .getString( "dialog", "error", "authentication_fallback_to_default")), MailResourceLoader.getString("dialog", "error", "authentication_process_error"), JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.OK_OPTION) { loginMethod = AuthenticationManager.USER; popItem.setString("login_method", Integer .toString(loginMethod)); } else { throw new CommandCancelledException(); } } }
Clone fragments detected by clone detection tool
File path: /columba-1.4-src/mail/src/main/java/org/columba/mail/imap/IMAPServer.java File path: /columba-1.4-src/mail/src/main/java/org/columba/mail/pop3/POP3Store.java
Method name: void login() Method name: void login()
Number of AST nodes: 7 Number of AST nodes: 7
1
try {
2
				if (loginMethod == AuthenticationManager.LOGIN) {
1
if (loginMethod == AuthenticationManager.
2
APOP) {
3
					try {
3
					protocol.login(item.get("user"), password);
4
						protocol.apop(popItem.get("user"), password);
4
					// If no exception happened we have successfully logged
5
					
5
					// in
6
					authenticated
6
} catch (POP3Exception e1) {
7
						// some server have a bogus apop
8
						// try user/pass to check if the password is
9
						// correct
10
						protocol.userPass(popItem.get("user"), password);
11
						LOG
12
								.warning(popItem.get("host")
13
										+ " : bogus APOP implementation -> falling back to USER/PASS.");
14
						// user/pass worked -> this is indeed
15
						// a bogus server.
16
					}
7
 = true;
17
					login = true;
8
				} else {
18
				} else {
9
					try {
19
					try {
10
						// AUTH
20
						// AUTH
11
						protocol.authenticate(AuthenticationManager
21
						protocol.auth(AuthenticationManager
12
								.getSaslName(loginMethod), item.get("user"),
22
								.getSaslName(loginMethod), popItem.get("user"),
13
								password);
23
								password);
14
						// If no exception happened we have successfully logged
24
						
15
						// in
16
						authenticated = true;
25
login = true;
17
					} catch (AuthenticationException e) {
26
					} catch (AuthenticationException e) {
18
						// If the cause is a IMAPExcpetion then only password
27
						// If the cause is a IMAPExcpetion then only password
19
						// wrong
28
						// wrong
20
						// else bogus authentication mechanism
29
						// else bogus authentication mechanism
21
						if (e.getCause() instanceof IMAPException)
30
						if (e.getCause() instanceof POP3Exception)
22
							throw (IMAPException) e.getCause();
31
							throw (POP3Exception) e.getCause();
23
						// Some error in the client/server communication
32
						// Some error in the client/server communication
24
						// --> fall back to default login process
33
						// --> fall back to default login process
25
						int result = JOptionPane
34
						int result = JOptionPane
26
								.showConfirmDialog(
35
								.showConfirmDialog(
27
										FrameManager.getInstance()
36
										FrameManager.getInstance()
28
												.getActiveFrame(),
37
												.getActiveFrame(),
29
										new MultiLineLabel(
38
										new MultiLineLabel(
30
												e.getMessage()
39
												e.getMessage()
31
														+ "\n"
40
														+ "\n"
32
														+ MailResourceLoader
41
														+ MailResourceLoader
33
																.getString(
42
																.getString(
34
																		"dialog",
43
																		"dialog",
35
																		"error",
44
																		"error",
36
																		"authentication_fallback_to_default")),
45
																		"authentication_fallback_to_default")),
37
										MailResourceLoader.getString("dialog",
46
										MailResourceLoader.getString("dialog",
38
												"error",
47
												"error",
39
												"authentication_process_error"),
48
												"authentication_process_error"),
40
										JOptionPane.OK_CANCEL_OPTION);
49
										JOptionPane.OK_CANCEL_OPTION);
41
						if (result == JOptionPane.OK_OPTION) {
50
						if (result == JOptionPane.OK_OPTION) {
42
							loginMethod = AuthenticationManager.LOGIN;
51
							loginMethod = AuthenticationManager.USER;
43
							item.setString("login_method", Integer
52
							popItem.setString("login_method", Integer
44
									.toString(loginMethod));
53
									.toString(loginMethod));
45
						} else {
54
						} else {
46
							throw new CommandCancelledException();
55
							throw new CommandCancelledException();
47
						}
56
						}
48
					}
57
					}
49
				}
58
				}
50
			} catch (IMAPException ex) {
51
				// login failed?
52
				IMAPResponse response = ex.getResponse();
53
				if (response == null || !response.isNO()) {
54
					// This exception is not because wrong username or
55
					// password
56
					throw ex;
57
				}
58
			}
Summary
Number of common nesting structure subtrees1
Number of refactorable cases0
Number of non-refactorable cases1
Time elapsed for finding largest common nesting structure subtrees (ms)2.6
Clones locationClones are in different classes
Number of node comparisons13
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements2
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment1
    Time elapsed for statement mapping (ms)39.4
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    24
    try
    24
    try
    23
    try
    Differences
    Expression1Expression2Difference
    org.columba.ristretto.imap.IMAPExceptionorg.columba.ristretto.pop3.POP3ExceptionSUBCLASS_TYPE_MISMATCH
    org.columba.ristretto.imap.IMAPExceptionorg.columba.ristretto.pop3.POP3ExceptionSUBCLASS_TYPE_MISMATCH
    LOGINUSERVARIABLE_NAME_MISMATCH
    itempopItemVARIABLE_NAME_MISMATCH
    org.columba.mail.config.ImapItemorg.columba.mail.config.PopItemSUBCLASS_TYPE_MISMATCH
    23
    try
                                                                                                                                                                                                  
    24
    protocol.auth(AuthenticationManager.getSaslName(loginMethod), popItem.get("user"), password);
    Preondition Violations
    Unmatched statement protocol.auth(AuthenticationManager.getSaslName(loginMethod),popItem.get("user"),password); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
    24
    protocol.auth(AuthenticationManager.getSaslName(loginMethod), popItem.get("user"), password);
    25
    protocol.authenticate(AuthenticationManager.getSaslName(loginMethod), item.get("user"), password);
    25
    protocol.authenticate(AuthenticationManager.getSaslName(loginMethod), item.get("user"), password);
    Preondition Violations
    Unmatched statement protocol.authenticate(AuthenticationManager.getSaslName(loginMethod),item.get("user"),password); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
                                                                                                                                                                                                            
    26
    authenticated = true;
    26
    authenticated = true;
    25
    login = true;
    Differences
    Expression1Expression2Difference
    authenticatedloginVARIABLE_NAME_MISMATCH
    25
    login = true;
    Precondition Violations (2)
    Row Violation
    1Unmatched statement protocol.auth(AuthenticationManager.getSaslName(loginMethod),popItem.get("user"),password); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
    2Unmatched statement protocol.authenticate(AuthenticationManager.getSaslName(loginMethod),item.get("user"),password); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted