bobobear / lambdaj

Automatically exported from code.google.com/p/lambdaj
Apache License 2.0
0 stars 0 forks source link

having() hides InvocationExceptions #15

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

    // the following code is free to modify and copy
    private static class PrivateBean2 {
        public String getFoo() {
            return "foo";
        }
    }

    @Test(expected=InvocationException.class)
    public void testThatHavingHideAccessViolationProblems(){
        PrivateBean2 bean = new PrivateBean2();

        Matcher matcher = having(on(PrivateBean2.class).getFoo(), equalTo("foo"));
        matcher.matches(bean); // this will cause access to a private class from
                               // the caller (which is HasArgumentWithValue).
    }

What is the expected output? What do you see instead?
As stated in the test I expected an InvocationException.

What version of the product are you using? On what operating system?
sources from the trunk.

Please provide any additional information below.

I think that the problem is in HasArgumentWithValue#matches() which ignores any 
exception returning false.

        // from HasArgumentWithValue.java
    public boolean matches(Object item) {
        if (argument == null) return false;
        try {
            return value.matches(argument.evaluate(item));
        } catch (Exception e) {
            return false;
        } 
    }

Original issue reported on code.google.com by andrea.f...@gmail.com on 27 Aug 2009 at 4:23

GoogleCodeExporter commented 9 years ago

Original comment by mario.fu...@gmail.com on 30 Aug 2009 at 5:49