New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message for unwrapped Collections #51

Closed
marcgs opened this Issue Oct 19, 2013 · 2 comments

Comments

Projects
None yet
2 participants
@marcgs

marcgs commented Oct 19, 2013

Currently the error message for a Class having a collection as a field which is initialized in constructor is: "Attempts to wrap mutable collection type using a non-whitelisted unmodifiable wrapper method". This is misleading, since in this case nothing is getting wrapped at all.

The goal of this issue is to improve this error message to something like "Not wrapped collection type". This mutability reason is detected by MutableTypeToFieldChecker.

Here a test which asserts the current error message

   public final static class ClassNotWrappingCollection {
        private final Collection<String> collection;

        public ClassNotWrappingCollection(Collection<String> collection) {
            this.collection = collection;
        }
    }

    @Test
    public void isImmutableMutableTypeToField_ClassNotWrappingCollection() throws Exception {
        try {
            assertImmutable(ClassNotWrappingCollection.class);
            fail("Error should be thrown");
        } catch (MutabilityAssertionError e) {
            assertThat(e.getMessage(), is("\n"+
                    "Expected: org.mutabilitydetector.ErrorLocationTest$ClassNotWrappingCollection to be IMMUTABLE\n" +
                    "     but: org.mutabilitydetector.ErrorLocationTest$ClassNotWrappingCollection is actually NOT_IMMUTABLE\n" +
                    "    Reasons:\n" +
                    "        Attempts to wrap mutable collection type using a non-whitelisted unmodifiable wrapper method. [Field: collection, Class: org.mutabilitydetector.ErrorLocationTest$ClassNotWrappingCollection]\n" +
                    "    Allowed reasons:\n" +
                    "        None."));
        }
    }
@Grundlefleck

This comment has been minimized.

Contributor

Grundlefleck commented Oct 19, 2013

Thanks, another to apply the newcomer tag to.

kwahsog pushed a commit to kwahsog/MutabilityDetector that referenced this issue Dec 30, 2015

kwahsog pushed a commit to kwahsog/MutabilityDetector that referenced this issue Jan 2, 2016

Grundlefleck added a commit that referenced this issue Jan 4, 2016

Merge pull request #69 from kwahsog/master
#51 - Error message improved for unwrapped Collections
@Grundlefleck

This comment has been minimized.

Contributor

Grundlefleck commented Jan 4, 2016

Now not so misleading, thanks @kwahsog!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment