- There is some code which the question asker thinks should work
- It doesn't work
- They have provided sufficient code in the question to enable it to be answered, and indeed it has answer(s)
- They have said what is wrong (e.g. "it throws a NullPointerException")
- What the code is supposed to do is clear enough
So clearly, one of the close reasons is inapplicable. But some people are deciding to vote to close anyway, using the reason "Off-topic: Questions asking for code must demonstrate a minimal understanding of the problem being solved". But they are not asking for code, they have written some code already, it just doesn't work!
I may have voted the same way a few times, and for that I apologise. I am now voting to leave open these questions (with a heavy heart because they are invariably very poorly-researched), because I don't think that is what that close reason is for, and sometimes I downvote the questions as well, but it disturbs me that there are several people seemingly abusing the close system to close questions they just don't think are very good quality or appropriate for the site, using invalid reasons. Not only does this set a bad precedent, it doesn't look good to the outside world to use invalid close reasons.
P.S. I think the NullPointerException ones could best be addressed by closing as a duplicate of a "canonical NullPointerException question for Java", which has been suggested to me on Meta before. But I haven't found such a canonical question yet.
Anyway, sometimes the questions I am talking about are not necessarily duplicates, just poorly-researched.