CPD Results

The following document contains the results of PMD's CPD

Duplications

FileLine
org/apache/geronimo/javamail/transport/smtp/SMTPTransport.java1094
org/apache/geronimo/javamail/transport/smtp/SMTPTransport.java1216
                    int socketFactoryPort = getIntProtocolProperty(MAIL_SMTP_FACTORY_PORT, -1);

                    // we choose the port used by the socket based on overrides.
                    Integer portArg = new Integer(socketFactoryPort == -1 ? port : socketFactoryPort);

                    // use the current context loader to resolve this.
                    ClassLoader loader = Thread.currentThread().getContextClassLoader();
                    Class factoryClass = loader.loadClass(socketFactory);

                    // done indirectly, we need to invoke the method using
                    // reflection.
                    // This retrieves a factory instance.
                    Method getDefault = factoryClass.getMethod("getDefault", new Class[0]);
                    Object defFactory = getDefault.invoke(new Object(), new Object[0]);

                    // now that we have the factory, there are two different
                    // createSocket() calls we use,
                    // depending on whether we have a localAddress override.

                    if (localAddress != null) {
                        // retrieve the createSocket(String, int, InetAddress,
                        // int) method.
                        Class[] createSocketSig = new Class[] { String.class, Integer.TYPE, InetAddress.class,
                                Integer.TYPE };
                        Method createSocket = factoryClass.getMethod("createSocket", createSocketSig);

                        Object[] createSocketArgs = new Object[] { host, portArg, localAddress, new Integer(localPort) };
                        socket = (Socket) createSocket.invoke(defFactory, createSocketArgs);
                    } else {
                        // retrieve the createSocket(String, int) method.
                        Class[] createSocketSig = new Class[] { String.class, Integer.TYPE };
                        Method createSocket = factoryClass.getMethod("createSocket", createSocketSig);

                        Object[] createSocketArgs = new Object[] { host, portArg };
                        socket = (Socket) createSocket.invoke(defFactory, createSocketArgs);
                    }
                } catch (Throwable e) {
                    // if we're allowed to fallback, then use the default
                    // factory and try this again. We only
                    // allow this to happen once.
                    if (fallback) {

FileLine
org/apache/geronimo/javamail/transport/nntp/NNTPConnection.java326
org/apache/geronimo/javamail/transport/smtp/SMTPTransport.java1094
                int socketFactoryPort = getIntProtocolProperty(MAIL_SMTP_FACTORY_PORT, -1);

                // we choose the port used by the socket based on overrides.
                Integer portArg = new Integer(socketFactoryPort == -1 ? port : socketFactoryPort);

                // use the current context loader to resolve this.
                ClassLoader loader = Thread.currentThread().getContextClassLoader();
                Class factoryClass = loader.loadClass(socketFactory);

                // done indirectly, we need to invoke the method using
                // reflection.
                // This retrieves a factory instance.
                Method getDefault = factoryClass.getMethod("getDefault", new Class[0]);
                Object defFactory = getDefault.invoke(new Object(), new Object[0]);

                // now that we have the factory, there are two different
                // createSocket() calls we use,
                // depending on whether we have a localAddress override.

                if (localAddress != null) {
                    // retrieve the createSocket(String, int, InetAddress, int)
                    // method.
                    Class[] createSocketSig = new Class[] { String.class, Integer.TYPE, InetAddress.class, Integer.TYPE };
                    Method createSocket = factoryClass.getMethod("createSocket", createSocketSig);

                    Object[] createSocketArgs = new Object[] { host, portArg, localAddress, new Integer(localPort) };
                    socket = (Socket) createSocket.invoke(defFactory, createSocketArgs);
                } else {
                    // retrieve the createSocket(String, int) method.
                    Class[] createSocketSig = new Class[] { String.class, Integer.TYPE };
                    Method createSocket = factoryClass.getMethod("createSocket", createSocketSig);

                    Object[] createSocketArgs = new Object[] { host, portArg };
                    socket = (Socket) createSocket.invoke(defFactory, createSocketArgs);
                }
            } catch (Throwable e) {
                // if a socket factor is specified, then we may need to fall
                // back to a default. This behavior
                // is controlled by (surprise) more session properties.
                if (isProtocolPropertyTrue(MAIL_SMTP_FACTORY_FALLBACK)) {

FileLine
org/apache/geronimo/javamail/transport/nntp/NNTPConnection.java834
org/apache/geronimo/javamail/transport/smtp/SMTPTransport.java2124
        ClientAuthenticator authenticator = null;

        // now go through the progression of mechanisms we support, from the
        // most secure to the
        // least secure.

        if (supportsAuthentication(AUTHENTICATION_DIGESTMD5)) {
            authenticator = new DigestMD5Authenticator(host, username, password, getSASLRealm());
        } else if (supportsAuthentication(AUTHENTICATION_CRAMMD5)) {
            authenticator = new CramMD5Authenticator(username, password);
        } else if (supportsAuthentication(AUTHENTICATION_LOGIN)) {
            authenticator = new LoginAuthenticator(username, password);
        } else if (supportsAuthentication(AUTHENTICATION_PLAIN)) {
            authenticator = new PlainAuthenticator(username, password);
        } else {
            // can't find a mechanism we support in common
            return false;
        }

        if (debug) {
            debugOut("Authenticating for user: " + username + " using " + authenticator.getMechanismName());
        }

        // if the authenticator has some initial data, we compose a command
        // containing the initial data.
        if (authenticator.hasInitialResponse()) {
            StringBuffer command = new StringBuffer();
            // the auth command initiates the handshaking.
            command.append("AUTH ");

FileLine
org/apache/geronimo/javamail/store/nntp/NNTPStore.java264
org/apache/geronimo/javamail/transport/nntp/NNTPTransport.java293
        e.printStackTrace(debugStream);
    }

    /**
     * Get a property associated with this mail protocol.
     * 
     * @param name
     *            The name of the property.
     * 
     * @return The property value (returns null if the property has not been
     *         set).
     */
    String getProperty(String name) {
        // the name we're given is the least qualified part of the name. We
        // construct the full property name
        // using the protocol (either "nntp" or "nntp-post").
        String fullName = "mail." + protocol + "." + name;
        return session.getProperty(fullName);
    }

    /**
     * Get a property associated with this mail session. Returns the provided
     * default if it doesn't exist.
     * 
     * @param name
     *            The name of the property.
     * @param defaultValue
     *            The default value to return if the property doesn't exist.
     * 
     * @return The property value (returns defaultValue if the property has not
     *         been set).
     */
    String getProperty(String name, String defaultValue) {
        // the name we're given is the least qualified part of the name. We
        // construct the full property name
        // using the protocol (either "nntp" or "nntp-post").
        String fullName = "mail." + protocol + "." + name;
        return SessionUtil.getProperty(session, fullName, defaultValue);
    }

    /**
     * Get a property associated with this mail session as an integer value.
     * Returns the default value if the property doesn't exist or it doesn't
     * have a valid int value.
     * 
     * @param name
     *            The name of the property.
     * @param defaultValue
     *            The default value to return if the property doesn't exist.
     * 
     * @return The property value converted to an int.
     */
    int getIntProperty(String name, int defaultValue) {
        // the name we're given is the least qualified part of the name. We
        // construct the full property name
        // using the protocol (either "nntp" or "nntp-post").
        String fullName = "mail." + protocol + "." + name;
        return SessionUtil.getIntProperty(session, fullName, defaultValue);
    }

    /**
     * Get a property associated with this mail session as an boolean value.
     * Returns the default value if the property doesn't exist or it doesn't
     * have a valid int value.
     * 
     * @param name
     *            The name of the property.
     * @param defaultValue
     *            The default value to return if the property doesn't exist.
     * 
     * @return The property value converted to a boolean
     */
    boolean getBooleanProperty(String name, boolean defaultValue) {
        // the name we're given is the least qualified part of the name. We
        // construct the full property name
        // using the protocol (either "nntp" or "nntp-post").
        String fullName = "mail." + protocol + "." + name;
        return SessionUtil.getBooleanProperty(session, fullName, defaultValue);
    }
}

FileLine
org/apache/geronimo/javamail/store/nntp/NNTPStore.java265
org/apache/geronimo/javamail/transport/nntp/NNTPConnection.java1001
    }

    /**
     * Get a property associated with this mail protocol.
     * 
     * @param name
     *            The name of the property.
     * 
     * @return The property value (returns null if the property has not been
     *         set).
     */
    String getProperty(String name) {
        // the name we're given is the least qualified part of the name. We
        // construct the full property name
        // using the protocol (either "nntp" or "nntp-post").
        String fullName = "mail." + protocol + "." + name;
        return session.getProperty(fullName);
    }

    /**
     * Get a property associated with this mail session. Returns the provided
     * default if it doesn't exist.
     * 
     * @param name
     *            The name of the property.
     * @param defaultValue
     *            The default value to return if the property doesn't exist.
     * 
     * @return The property value (returns defaultValue if the property has not
     *         been set).
     */
    String getProperty(String name, String defaultValue) {
        // the name we're given is the least qualified part of the name. We
        // construct the full property name
        // using the protocol (either "nntp" or "nntp-post").
        String fullName = "mail." + protocol + "." + name;
        return SessionUtil.getProperty(session, fullName, defaultValue);
    }

    /**
     * Get a property associated with this mail session as an integer value.
     * Returns the default value if the property doesn't exist or it doesn't
     * have a valid int value.
     * 
     * @param name
     *            The name of the property.
     * @param defaultValue
     *            The default value to return if the property doesn't exist.
     * 
     * @return The property value converted to an int.
     */
    int getIntProperty(String name, int defaultValue) {
        // the name we're given is the least qualified part of the name. We
        // construct the full property name
        // using the protocol (either "nntp" or "nntp-post").
        String fullName = "mail." + protocol + "." + name;
        return SessionUtil.getIntProperty(session, fullName, defaultValue);
    }

    /**
     * Get a property associated with this mail session as an boolean value.
     * Returns the default value if the property doesn't exist or it doesn't
     * have a valid int value.
     * 
     * @param name
     *            The name of the property.
     * @param defaultValue
     *            The default value to return if the property doesn't exist.
     * 
     * @return The property value converted to a boolean
     */
    boolean getBooleanProperty(String name, boolean defaultValue) {
        // the name we're given is the least qualified part of the name. We
        // construct the full property name
        // using the protocol (either "nntp" or "nntp-post").
        String fullName = "mail." + protocol + "." + name;
        return SessionUtil.getBooleanProperty(session, fullName, defaultValue);
    }
}

FileLine
org/apache/geronimo/javamail/transport/nntp/NNTPConnection.java365
org/apache/geronimo/javamail/transport/smtp/SMTPTransport.java1133
                if (isProtocolPropertyTrue(MAIL_SMTP_FACTORY_FALLBACK)) {
                    if (debug) {
                        debugOut("First plain socket attempt faile, falling back to default factory", e);
                    }
                    socket = new Socket(host, port, localAddress, localPort);
                }
                // we have an exception. We're going to throw an IOException,
                // which may require unwrapping
                // or rewrapping the exception.
                else {
                    // we have an exception from the reflection, so unwrap the
                    // base exception
                    if (e instanceof InvocationTargetException) {
                        e = ((InvocationTargetException) e).getTargetException();
                    }

                    if (debug) {
                        debugOut("Plain socket creation failure", e);
                    }

                    // throw this as an IOException, with the original exception
                    // attached.
                    IOException ioe = new IOException("Error connecting to " + host + ", " + port);
                    ioe.initCause(e);
                    throw ioe;
                }
            }
        }

        if (timeout >= 0) {
            socket.setSoTimeout(timeout);
        }
    }