CPD Results

The following document contains the results of PMD's CPD 6.29.0.

Duplications

File Line
org/apache/log4j/xml/UtilLoggingXMLDecoder.java 160
org/apache/log4j/xml/XMLDecoder.java 162
new InputSource(new StringReader(buf.toString()));
            document = docBuilder.parse(inputSource);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return document;
    }

    /**
     * Decodes a File into a Vector of LoggingEvents.
     *
     * @param url the url of a file containing events to decode
     * @return Vector of LoggingEvents
     * @throws IOException if IO error during processing.
     */
    public Vector<LoggingEvent> decode(final URL url) throws IOException {
        LineNumberReader reader;
        boolean isZipFile = url.getPath().toLowerCase().endsWith(".zip");
        InputStream inputStream;
        if (isZipFile) {
            inputStream = new ZipInputStream(url.openStream());
            //move stream to next entry so we can read it
            ((ZipInputStream) inputStream).getNextEntry();
        } else {
            inputStream = url.openStream();
        }
        if (owner != null) {
            reader = new LineNumberReader(
                new InputStreamReader(
                    new ProgressMonitorInputStream(owner,
                        "Loading " + url, inputStream), ENCODING));
        } else {
            reader = new LineNumberReader(new InputStreamReader(inputStream, ENCODING));
        }
        Vector<LoggingEvent> v = new Vector<>();

        String line;
        Vector<LoggingEvent> events;
        try {
            while ((line = reader.readLine()) != null) {
                StringBuilder buffer = new StringBuilder(line);
                for (int i = 0; i < 1000; i++) {
                    buffer.append(reader.readLine()).append("\n");
                }
                events = decodeEvents(buffer.toString());
                if (events != null) {
                    v.addAll(events);
                }
            }
        } finally {
            partialEvent = null;
            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return v;
    }

    /**
     * Decodes a String representing a number of events into a
     * Vector of LoggingEvents.
     *
     * @param document to decode events from
     * @return Vector of LoggingEvents
     */
    public Vector<LoggingEvent> decodeEvents(final String document) {

        if (document != null) {

            if (document.trim().equals("")) {
                return null;
            }

            String newDoc;
            String newPartialEvent = null;
            //separate the string into the last portion ending with </record>
            // (which will be processed) and the partial event which
            // will be combined and processed in the next section

            //if the document does not contain a record end,
            // append it to the partial event string
            if (document.lastIndexOf(RECORD_END) == -1) {
                partialEvent = partialEvent + document;
                return null;
            }

            if (document.lastIndexOf(RECORD_END) + RECORD_END.length()
                < document.length()) {
                newDoc = document.substring(0,
                    document.lastIndexOf(RECORD_END) + RECORD_END.length());
                newPartialEvent = document.substring(
                    document.lastIndexOf(RECORD_END) + RECORD_END.length());
            } else {
                newDoc = document;
            }
            if (partialEvent != null) {
                newDoc = partialEvent + newDoc;
            }
            partialEvent = newPartialEvent;

            Document doc = parse(newDoc);
            if (doc == null) {
                return null;
            }
            return decodeEvents(doc);
        }
        return null;
    }

    /**
     * Converts the string data into an XML Document, and then soaks out the
     * relevant bits to form a new LoggingEvent instance which can be used
     * by any Log4j element locally.
     *
     * @param data XML fragment
     * @return a single LoggingEvent or null
     */
    public LoggingEvent decode(final String data) {
        Document document = parse(data);

        if (document == null) {
            return null;
        }

        Vector<LoggingEvent> events = decodeEvents(document);

        if (events.size() > 0) {
            return events.firstElement();
        }

        return null;
    }

    /**
     * Given a Document, converts the XML into a Vector of LoggingEvents.
     *
     * @param document XML document
     * @return Vector of LoggingEvents
     */
    private Vector<LoggingEvent> decodeEvents(final Document document) {
        Vector<LoggingEvent> events = new Vector<>();
File Line
org/apache/log4j/chainsaw/icons/LineIconFactory.java 44
org/apache/log4j/chainsaw/icons/LineIconFactory.java 77
public static Icon createExpandIcon() {
        int size = 8;
        int xOffSet = 0;
        int yOffSet = 0;
        try {
            GraphicsEnvironment environment =
                GraphicsEnvironment.getLocalGraphicsEnvironment();
            BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
            Graphics2D g2D =
                environment.createGraphics(
                    image);
            g2D.setBackground(new Color(0, 0, 0, 0));
            g2D.clearRect(0, 0, size, size);
            g2D.setStroke(new BasicStroke(1.5f));
            g2D.setRenderingHint(
                RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
            g2D.setColor(Color.black);
            g2D.drawLine(
                xOffSet, (size / 2) + yOffSet, size - xOffSet,
                (size / 2) + yOffSet);
File Line
org/apache/log4j/net/MulticastAppender.java 84
org/apache/log4j/net/UDPAppender.java 104
super(false);
    }

    /**
     * Open the multicast sender for the <b>RemoteHost</b> and <b>Port</b>.
     */
    public void activateOptions() {
        try {
            hostname = InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException uhe) {
            try {
                hostname = InetAddress.getLocalHost().getHostAddress();
            } catch (UnknownHostException uhe2) {
                hostname = "unknown";
            }
        }

        //allow system property of application to be primary
        if (application == null) {
            application = System.getProperty(Constants.APPLICATION_KEY);
        } else {
            if (System.getProperty(Constants.APPLICATION_KEY) != null) {
                application = application + "-" + System.getProperty(Constants.APPLICATION_KEY);
            }
        }

        if (remoteHost != null) {
            address = getAddressByName(remoteHost);
File Line
org/apache/log4j/xml/XMLDecoder.java 357
org/apache/log4j/xml/XMLDecoder.java 397
NodeList propertyList = list.item(y).getChildNodes();
                    int propertyLength = propertyList.getLength();

                    for (int i = 0; i < propertyLength; i++) {
                        String propertyTag = propertyList.item(i).getNodeName();

                        if (propertyTag.equalsIgnoreCase("log4j:data")) {
                            Node property = propertyList.item(i);
                            String name =
                                property.getAttributes().getNamedItem("name").getNodeValue();
                            String value =
                                property.getAttributes().getNamedItem("value").getNodeValue();
                            properties.put(name, value);
                        }
                    }
                }

                if (tagName.equalsIgnoreCase("log4j:throwable")) {
File Line
org/apache/log4j/chainsaw/LogPanel.java 3857
org/apache/log4j/chainsaw/LogPanel.java 3877
} else if (e.getType() == TableModelEvent.DELETE) {
                    //find each eventwrapper with an id in the deleted range and remove it...
//                        System.out.println("delete- current warnings: " + warnings.size() + ", errors: " + errors.size() + ", first row: " + firstRow + ", last row: " + lastRow + ", displayed event count: " + displayedEvents.size() );
                    for (Iterator<ThumbnailLoggingEventWrapper> iter = secondaryList.iterator(); iter.hasNext(); ) {
                        ThumbnailLoggingEventWrapper wrapper = iter.next();
                        if ((wrapper.rowNum >= firstRow) && (wrapper.rowNum <= lastRow)) {
//                                System.out.println("deleting find: " + wrapper);
                            iter.remove();
                        }
                    }
                    for (Iterator<ThumbnailLoggingEventWrapper> iter = primaryList.iterator(); iter.hasNext(); ) {
                        ThumbnailLoggingEventWrapper wrapper = iter.next();
                        if ((wrapper.rowNum >= firstRow) && (wrapper.rowNum <= lastRow)) {
//                                System.out.println("deleting error: " + wrapper);
                            iter.remove();
                        }
                    }
File Line
org/apache/log4j/xml/UtilLoggingXMLDecoder.java 410
org/apache/log4j/xml/XMLDecoder.java 426
}
            }

            LocationInfo info;
            if ((fileName != null)
                || (className != null)
                || (methodName != null)
                || (lineNumber != null)) {
                info = new LocationInfo(fileName, className, methodName, lineNumber);
            } else {
                info = LocationInfo.NA_LOCATION_INFO;
            }

            ThrowableInformation throwableInfo = null;
            if (exception != null) {
                throwableInfo = new ThrowableInformation(exception);
            }

            LoggingEvent loggingEvent = new LoggingEvent(null,
                logger, timeStamp, level, message,
                threadName,
                throwableInfo,
                ndc,
                info,
                properties);

            events.add(loggingEvent);
File Line
org/apache/log4j/chainsaw/LogPanel.java 3634
org/apache/log4j/chainsaw/LogPanel.java 3710
i++;
                //only add if there is a color defined
                if (primaryMatches(wrapper)) {
                    primaryList.add(wrapper);
                }
            }
            revalidate();
            repaint();
        }

        public void paintComponent(Graphics g) {
            super.paintComponent(g);

            int rowCount = table.getRowCount();
            if (rowCount == 0) {
                return;
            }
            //use event pane height as reference height - max component height will be extended by event height if
            // last row is rendered, so subtract here
            int height = eventsPane.getHeight();
            int maxHeight = Math.min(maxEventHeight, (height / rowCount));
            int minHeight = Math.max(1, maxHeight);
            int componentHeight = height - minHeight;
            int eventHeight = minHeight;

            //draw all events
            for (Object aPrimaryList : primaryList) {
File Line
org/apache/log4j/xml/UtilLoggingXMLDecoder.java 438
org/apache/log4j/xml/XMLDecoder.java 462
}
        return events;
    }

    /**
     * Get contents of CDATASection.
     *
     * @param n CDATASection
     * @return text content of all text or CDATA children of node.
     */
    private String getCData(final Node n) {
        StringBuilder buf = new StringBuilder();
        NodeList nl = n.getChildNodes();

        for (int x = 0; x < nl.getLength(); x++) {
            Node innerNode = nl.item(x);

            if (
                (innerNode.getNodeType() == Node.TEXT_NODE)
                    || (innerNode.getNodeType() == Node.CDATA_SECTION_NODE)) {
                buf.append(innerNode.getNodeValue());
            }
        }

        return buf.toString();
    }
}