I am writing API, so my API will be used from external modules. And here is a one of methods where I can't figure out what to use assertion or java.lang.IllegalArgumentException
/**
* Adds translation of information to underlying store for particular language
* @param languageId The identifier of the language
* @param translation The translation provided for the specific language
* @throws AssertionError if the provided language id is {@code null} or empty
* or provided translation is {@code null} or empty
*/
public final void addTranslation(String languageId, String translation){
assert !(Strings.isNullOrEmpty(languageId));
assert !(Strings.isNullOrEmpty(translation));
translations.put(languageId, translation);
}
If I use runtime exception, I think that it may harm the execution of the application which is using this API. If I use assertion then it will harm my API, if the assertion flag is disabled.
Also tried to read similar post When to use an assertion and when to use an exception. But it is bit confusing to detect which case is mine.
Is there a strictly defined way, where to use assertions and where to use runtime exceptions?