Skip to content

Input Validation for Non-String Data Types #12

Description

@sanvviratthore

The current implementation of the contains method does not perform any input validation. As a result, it may lead to unexpected behavior or runtime exceptions if non-string data types are passed as arguments. This can occur when:

  • Users mistakenly pass null, which can lead to a NullPointerException.

To enhance the robustness of the isContains method, consider implementing the following input validation measures:

  1. Null checks: Before processing the input strings, check if either string is null. If so, return an appropriate message or boolean value indicating that the operation cannot be performed. For example:

if (str1 == null || str2 == null) {
throw new IllegalArgumentException("Input strings cannot be null.");
}

  1. String Empty Checks: Check if the strings are empty before proceeding. An empty string might lead to confusion regarding whether it contains another string.

if (str1.isEmpty() || str2.isEmpty()) {
throw new IllegalArgumentException("Input strings cannot be empty.");
}

  • This will improve reliability and enhanced user experience.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions