clarkware / jdepend

A Java package dependency analyzer that generates design quality metrics.
MIT License
663 stars 132 forks source link

DependencyConstraint match is incorrect in version 2.9.1 #5

Open krueger71 opened 10 years ago

krueger71 commented 10 years ago

In version 2.9.1 this method ends prematurely on the first successful package match

public boolean match(Collection expectedPackages) {

        if (packages.size() == expectedPackages.size()) {

            for (Iterator i = expectedPackages.iterator(); i.hasNext();) {
                Object next = i.next();
                if (next instanceof JavaPackage) {
                    JavaPackage nextPackage = (JavaPackage) next;
                    if (!matchPackage(nextPackage)) {
                        return false;
                    }
                } else {
                    break;
                }

                return true;
            }
        }

        return false;
    }

This version works as expected, letting all packages be matched before returning true

    public boolean match(Collection expectedPackages) {

        if (packages.size() == expectedPackages.size()) {

            for (Iterator i = expectedPackages.iterator(); i.hasNext();) {
                Object next = i.next();
                if (next instanceof JavaPackage) {
                    JavaPackage nextPackage = (JavaPackage) next;
                    if (!matchPackage(nextPackage)) {
                        return false;
                    }
                }
            }
            return true;
        }

        return false;
    }