-
Notifications
You must be signed in to change notification settings - Fork 177
Return Object.class from Instances#getType instead of throwing an exc… #162
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
import de.danielbechler.util.Assert; | ||
import de.danielbechler.util.Classes; | ||
import de.danielbechler.util.Collections; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Collection; | ||
import java.util.Map; | ||
|
@@ -28,6 +30,7 @@ | |
|
||
public class Instances | ||
{ | ||
private static final Logger logger = LoggerFactory.getLogger(Instances.class); | ||
private final Accessor sourceAccessor; | ||
private final Object working; | ||
private final Object base; | ||
|
@@ -225,8 +228,10 @@ else if (sourceAccessorType != null) | |
// special handling for beans and arrays should go here | ||
} | ||
} | ||
throw new IllegalArgumentException("Detected instances of different types " + types + ". " + | ||
"Instances must either be null or have the exact same type."); | ||
|
||
logger.info("Detected instances of different types " + types + ". " + | ||
"Instances should normally either be null or have the exact same type."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So far so good. Maybe replace "Instances should normally either be null or have the exact same type" with something along the lines of "These objects will only be compared via equals method". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
return Object.class; | ||
} | ||
|
||
private Class<?> tryToGetTypeFromSourceAccessor() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a pretty big change from the original implementation. The exception basically guaranteed, that people don't accidentally compare objects of different types. Now it just silently changes the comparison strategy to "equals only", which is pretty easy to miss.
I think it would be nice to have a little debug message, to make it slightly more obvious and potentially save some poor souls from countless hours of frustrating debugging. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. I added an info message - what do you think about the wording?