Back to success stories

Sample of Defect

Project Name CID Checker Category Developer Description
zaproxy/zaproxy 117882 COPY_PASTE_ERROR Incorrect expression Copy & paste errors might not often cause system crashes, but developer headaches. Unexpected behavior can be pain to hunt down when one of these is involved. I currently know no other static analysis tool than Coverity that finds those nasty buggers! :-)
File: /src/org/zaproxy/zap/model/Context.java
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }
        }
        }
        
        private void restructureSiteTreeEventHandler() {
                log.debug("Restructure site tree for context: " + this.getName());
                
                HttpMessage msg;
                SiteNode sn2;

                for (SiteNode sn: this.getNodesInContextFromSiteTree()) {
                        log.debug("Restructure site tree, node: " + sn.getNodeName());
                        try {
                                msg = sn.getHistoryReference().getHttpMessage();
                                if (msg != null) {
                                        sn2 = session.getSiteTree().findNode(msg, sn.getChildCount() > 0);
                                        if (sn2 == null) {
                                                sn2 = session.getSiteTree().addPath(sn.getHistoryReference(), msg);
                                        }
                                                
                                        if (! sn2.equals(sn)) {
                                                // TODO: Might be better in a 'merge'? Do we need to copy other things, list custom icons? 
 <<< CID 117882: Incorrect expression COPY_PASTE_ERROR
 <<< "sn" in "sn.getAlerts()" looks like a copy-paste error.
 < Should it say "sn2" instead?
534
535
536
                                                for (Alert alert : sn.getAlerts()) {
                                                        sn2.addAlert(alert);
                                                }
 << "sn.getAlerts()" looks like the original copy.
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
                                                for (Alert alert : sn.getAlerts()) {
                                                        sn.deleteAlert(alert);
                                                }
                                                session.getSiteTree().removeNodeFromParent(sn);
                                        }
                                }
                        } catch (Exception e) {
                                log.error(e.getMessage(), e);
                        }
                }
        }

        /**
         * Creates a copy of the Context. The copy is deep, with the exception of the TechSet.
         * 
         * @return the context
         */
        public Context duplicate() {
                Context newContext = new Context(session, getIndex());
                newContext.description = this.description;
                newContext.name = this.name;
                newContext.includeInRegexs = new ArrayList<>(this.includeInRegexs);
                newContext.includeInPatterns = new ArrayList<>(this.includeInPatterns);
                newContext.excludeFromRegexs = new ArrayList<>(this.excludeFromRegexs);
                newContext.excludeFromPatterns = new ArrayList<>(this.excludeFromPatterns);
                newContext.inScope = this.inScope;
                newContext.techSet = new TechSet(this.techSet);
Events:
remediation Context.java:534
original Context.java:537
copy_paste_error Context.java:534