Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Improve error message for Collections being wrapped without safe copy #52
Currently the error message for a collection field being wrapped without a safe copy is "Attempts to wrap mutable collection type without safely performing a copy first". It would be useful to provide a hint how a safe copy can be performed for the current use case. For instance for a List this can be achieved with:
The goal of this issue is to improve the current error message with such hints how the copy can be done so that Mutability Detector does not report an error anymore.
Here a test which asserts the current error message:
But I want to add type parameter to constructor call because java compiler generates warning:
To do this I need to resolve type parameter
I already googled ASM signature visitors, but I hope there is easier way.
There is existing code elsewhere which retrieves the generic type of a collection, when assigned to a field. In that case it's used to say e.g.
Let me know if that helps :)
Thank you for fast reply.
This is almost what I need.
is equal to
which is bad for my particular case.
Anyway, many thanks for providing starting point for me.
Please, help me with one more question.
private List<? extends A> list;
private List<? super A> list;
What hint do you think will be the most correct?
I can think of two cases here:
Personally I tend to chose answer 1, but anyway please tell me your opinion.
added a commit
Jan 25, 2016
I think this issue has been addressed by @badgersow, the output will now look like:
Which is a great improvement.