-
Notifications
You must be signed in to change notification settings - Fork 15
[CUS-11475] Added existing nlp to all application types. #361
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
base: dev
Are you sure you want to change the base?
Changes from all 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 |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| package com.testsigma.addons.android; | ||
|
|
||
| import com.testsigma.sdk.AndroidAction; | ||
| import com.testsigma.sdk.ApplicationType; | ||
| import com.testsigma.sdk.annotation.Action; | ||
| import com.testsigma.sdk.annotation.TestData; | ||
| import com.testsigma.sdk.annotation.RunTimeData; | ||
| import lombok.Data; | ||
| import org.apache.commons.lang3.exception.ExceptionUtils; | ||
| import org.openqa.selenium.NoSuchElementException; | ||
| import java.time.LocalDateTime; | ||
| import java.time.LocalTime; | ||
| import java.time.format.DateTimeFormatter; | ||
| import java.time.format.DateTimeParseException; | ||
|
|
||
| @Data | ||
| @Action(actionText = "Add minute minutes to the input-datetime with input-datetime-format, convert to output-datetime-format format, and store it in a runtime variable variable-name", | ||
| description = "Adds specified minutes to a given input datetime, converts the resulting datetime to a specified date-time format, and stores it in a runtime variable", | ||
| applicationType = ApplicationType.ANDROID, | ||
| useCustomScreenshot = false) | ||
| public class AddMinutesToDateTime extends AndroidAction { | ||
|
|
||
| @TestData(reference = "input-datetime") | ||
| private com.testsigma.sdk.TestData dateTime; | ||
| @TestData(reference = "input-datetime-format") | ||
| private com.testsigma.sdk.TestData inputFormat; | ||
| @TestData(reference = "output-datetime-format") | ||
| private com.testsigma.sdk.TestData outputFormat; | ||
| @TestData(reference = "minute") | ||
| private com.testsigma.sdk.TestData minutesToAdd; | ||
|
|
||
| @TestData(reference = "variable-name", isRuntimeVariable = true) | ||
| private com.testsigma.sdk.TestData variableName; | ||
|
|
||
| @RunTimeData | ||
| private com.testsigma.sdk.RunTimeData runTimeData; | ||
|
|
||
| @Override | ||
| public com.testsigma.sdk.Result execute() throws NoSuchElementException { | ||
| logger.info("Initiating execution"); | ||
| com.testsigma.sdk.Result result = com.testsigma.sdk.Result.SUCCESS; | ||
| String dateTimeString = dateTime.getValue().toString(); | ||
| String inputFormatString = inputFormat.getValue().toString(); | ||
| String outputFormatString = outputFormat.getValue().toString(); | ||
| String minutesToAddString = minutesToAdd.getValue().toString(); | ||
| String variableNameString = variableName.getValue().toString(); | ||
|
|
||
| try { | ||
| int minutes = Integer.parseInt(minutesToAddString); | ||
|
|
||
| if (minutes < 0) { | ||
| result = com.testsigma.sdk.Result.FAILED; | ||
| setErrorMessage("The 'minute' value must be a non-negative integer."); | ||
| logger.warn("Invalid input: 'minute' value is negative."); | ||
| return result; | ||
| } | ||
|
|
||
| String newDateTime = addMinutesToDateTime(dateTimeString, inputFormatString, outputFormatString, minutes); | ||
|
|
||
| logger.info("New date-time value: " + newDateTime); | ||
|
|
||
| if (newDateTime != null) { | ||
| runTimeData.setValue(newDateTime); | ||
| runTimeData.setKey(variableNameString); | ||
| logger.info("Final value stored in variable '" + variableNameString + "' with value '" + newDateTime + "'"); | ||
| setSuccessMessage(String.format("Added %s minutes to %s and stored the output in '%s' format. %s : %s", | ||
| minutes, dateTimeString, outputFormatString, variableNameString, newDateTime)); | ||
| } else { | ||
| result = com.testsigma.sdk.Result.FAILED; | ||
| setErrorMessage("Failed to add minutes. Please check the input datetime, input datetime format, and output datetime format."); | ||
| } | ||
|
|
||
| } catch (NumberFormatException e) { | ||
| result = com.testsigma.sdk.Result.FAILED; | ||
| setErrorMessage("Invalid number format for 'minutes': " + minutesToAddString); | ||
| logger.warn("NumberFormatException: " + e); | ||
|
|
||
| } catch (Exception e) { | ||
| result = com.testsigma.sdk.Result.FAILED; | ||
| setErrorMessage("An unexpected error occurred: " + ExceptionUtils.getMessage(e)); | ||
| logger.warn("Exception during execution: " + ExceptionUtils.getStackTrace(e)); | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| public String addMinutesToDateTime(String dateTimeString, String inputFormatString, String outputFormatString, int minutesToAdd) { | ||
| try { | ||
| DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern(inputFormatString); | ||
|
|
||
| if (inputFormatString.contains("HH") || inputFormatString.contains("mm") || inputFormatString.contains("ss")) { | ||
| DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputFormatString); | ||
| LocalTime time = LocalTime.parse(dateTimeString, inputFormatter); | ||
| LocalTime newTime = time.plusMinutes(minutesToAdd); | ||
| logger.info("Successfully added minutes to the input time"); | ||
|
|
||
| return newTime.format(outputFormatter); | ||
|
|
||
| } else { | ||
|
|
||
| DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputFormatString); | ||
| LocalDateTime dateTime = LocalDateTime.parse(dateTimeString, inputFormatter); | ||
|
|
||
| LocalDateTime newDateTime = dateTime.plusMinutes(minutesToAdd); | ||
| logger.info("Successfully added minutes to the input datetime"); | ||
|
|
||
| return newDateTime.format(outputFormatter); | ||
| } | ||
|
|
||
| } catch (DateTimeParseException e) { | ||
| String errorMessage = "Invalid date/time format. Please use the format: " + inputFormatString + ". Error: " + e.getMessage(); | ||
| logger.warn(errorMessage); | ||
| setErrorMessage(errorMessage); | ||
| return null; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| package com.testsigma.addons.android; | ||
|
|
||
| import com.testsigma.sdk.AndroidAction; | ||
| import com.testsigma.sdk.ApplicationType; | ||
| import com.testsigma.sdk.annotation.Action; | ||
| import com.testsigma.sdk.annotation.TestData; | ||
| import com.testsigma.sdk.annotation.RunTimeData; | ||
| import lombok.Data; | ||
| import org.apache.commons.lang3.exception.ExceptionUtils; | ||
| import org.openqa.selenium.NoSuchElementException; | ||
| import java.time.LocalDateTime; | ||
| import java.time.LocalTime; | ||
| import java.time.format.DateTimeFormatter; | ||
| import java.time.format.DateTimeParseException; | ||
|
|
||
| @Data | ||
| @Action(actionText = "Subtract minute minutes to the input-datetime with input-datetime-format, convert to output-datetime-format format, and store it in a runtime variable variable-name", | ||
| description = "Subtracts specified minutes to a given input datetime, converts the resulting datetime to a specified date-time format, and stores it in a runtime variable", | ||
|
Comment on lines
+17
to
+18
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. Use "from" in the subtraction metadata. These strings are user-facing, and both 🤖 Prompt for AI Agents |
||
| applicationType = ApplicationType.ANDROID, | ||
| useCustomScreenshot = false) | ||
| public class SubtractMinutesToDateTime extends AndroidAction { | ||
|
|
||
| @TestData(reference = "input-datetime") | ||
| private com.testsigma.sdk.TestData dateTime; | ||
| @TestData(reference = "input-datetime-format") | ||
| private com.testsigma.sdk.TestData inputFormat; | ||
| @TestData(reference = "output-datetime-format") | ||
| private com.testsigma.sdk.TestData outputFormat; | ||
| @TestData(reference = "minute") | ||
| private com.testsigma.sdk.TestData minutesToAdd; | ||
|
|
||
| @TestData(reference = "variable-name", isRuntimeVariable = true) | ||
| private com.testsigma.sdk.TestData variableName; | ||
|
|
||
| @RunTimeData | ||
| private com.testsigma.sdk.RunTimeData runTimeData; | ||
|
|
||
| @Override | ||
| public com.testsigma.sdk.Result execute() throws NoSuchElementException { | ||
| logger.info("Initiating execution"); | ||
| com.testsigma.sdk.Result result = com.testsigma.sdk.Result.SUCCESS; | ||
| String dateTimeString = dateTime.getValue().toString(); | ||
| String inputFormatString = inputFormat.getValue().toString(); | ||
| String outputFormatString = outputFormat.getValue().toString(); | ||
| String minutesToAddString = minutesToAdd.getValue().toString(); | ||
| String variableNameString = variableName.getValue().toString(); | ||
|
|
||
| try { | ||
| int minutes = Integer.parseInt(minutesToAddString); | ||
|
|
||
| if (minutes < 0) { | ||
| result = com.testsigma.sdk.Result.FAILED; | ||
| setErrorMessage("The 'minute' value must be a non-negative integer."); | ||
| logger.warn("Invalid input: 'minute' value is negative."); | ||
| return result; | ||
| } | ||
|
|
||
| String newDateTime = subtractMinutesToDateTime(dateTimeString, inputFormatString, outputFormatString, minutes); | ||
|
|
||
| logger.info("New date-time value: " + newDateTime); | ||
|
|
||
| if (newDateTime != null) { | ||
| runTimeData.setValue(newDateTime); | ||
| runTimeData.setKey(variableNameString); | ||
| logger.info("Final value stored in variable '" + variableNameString + "' with value '" + newDateTime + "'"); | ||
| setSuccessMessage(String.format("Subtracted %s minutes from %s and stored the output in '%s' format. %s : %s", | ||
| minutes, dateTimeString, outputFormatString, variableNameString, newDateTime)); | ||
| } else { | ||
| result = com.testsigma.sdk.Result.FAILED; | ||
| setErrorMessage("Failed to subtract minutes. Please check the input datetime, input datetime format, and output datetime format."); | ||
| } | ||
|
|
||
| } catch (NumberFormatException e) { | ||
| result = com.testsigma.sdk.Result.FAILED; | ||
| setErrorMessage("Invalid number format for 'minutes': " + minutesToAddString); | ||
| logger.warn("NumberFormatException: " + e); | ||
|
|
||
| } catch (Exception e) { | ||
| result = com.testsigma.sdk.Result.FAILED; | ||
| setErrorMessage("An unexpected error occurred: " + ExceptionUtils.getMessage(e)); | ||
| logger.warn("Exception during execution: " + ExceptionUtils.getStackTrace(e)); | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| public String subtractMinutesToDateTime(String dateTimeString, String inputFormatString, String outputFormatString, int minutesToSubtract) { | ||
| try { | ||
| DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern(inputFormatString); | ||
|
|
||
| if (inputFormatString.contains("HH") || inputFormatString.contains("mm") || inputFormatString.contains("ss")) { | ||
| DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputFormatString); | ||
| LocalTime time = LocalTime.parse(dateTimeString, inputFormatter); | ||
| LocalTime newTime = time.minusMinutes(minutesToSubtract); | ||
| logger.info("Successfully subtracted minutes from the input time"); | ||
|
|
||
| return newTime.format(outputFormatter); | ||
|
|
||
| } else { | ||
|
|
||
| DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputFormatString); | ||
| LocalDateTime dateTime = LocalDateTime.parse(dateTimeString, inputFormatter); | ||
|
|
||
| LocalDateTime newDateTime = dateTime.minusMinutes(minutesToSubtract); | ||
| logger.info("Successfully subtracted minutes from the input datetime"); | ||
|
|
||
| return newDateTime.format(outputFormatter); | ||
|
Comment on lines
+90
to
+106
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. 🧩 Analysis chain🏁 Script executed: # First, let's find and read the full method context
find . -type f -name "SubtractMinutesToDateTime.java" | head -5Repository: testsigmahq/testsigma-addons Length of output: 1887 🏁 Script executed: # Get the file size and read the relevant section with context
wc -l add_minutes_to_the_specific_date_time_and_store_the_output_in_specific_format/src/main/java/com/testsigma/addons/android/SubtractMinutesToDateTime.javaRepository: testsigmahq/testsigma-addons Length of output: 1887 🏁 Script executed: # Read the entire file to understand context
cat -n add_minutes_to_the_specific_date_time_and_store_the_output_in_specific_format/src/main/java/com/testsigma/addons/android/SubtractMinutesToDateTime.javaRepository: testsigmahq/testsigma-addons Length of output: 1887 Use The Replace the conditional logic with Proposed fix- if (inputFormatString.contains("HH") || inputFormatString.contains("mm") || inputFormatString.contains("ss")) {
- DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputFormatString);
- LocalTime time = LocalTime.parse(dateTimeString, inputFormatter);
- LocalTime newTime = time.minusMinutes(minutesToSubtract);
- logger.info("Successfully subtracted minutes from the input time");
-
- return newTime.format(outputFormatter);
-
- } else {
-
- DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputFormatString);
- LocalDateTime dateTime = LocalDateTime.parse(dateTimeString, inputFormatter);
-
- LocalDateTime newDateTime = dateTime.minusMinutes(minutesToSubtract);
- logger.info("Successfully subtracted minutes from the input datetime");
-
- return newDateTime.format(outputFormatter);
- }
+ DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputFormatString);
+ java.time.temporal.TemporalAccessor parsed =
+ inputFormatter.parseBest(dateTimeString, LocalDateTime::from, LocalTime::from);
+
+ if (parsed instanceof LocalDateTime) {
+ LocalDateTime newDateTime = ((LocalDateTime) parsed).minusMinutes(minutesToSubtract);
+ logger.info("Successfully subtracted minutes from the input datetime");
+ return newDateTime.format(outputFormatter);
+ }
+
+ LocalTime newTime = ((LocalTime) parsed).minusMinutes(minutesToSubtract);
+ logger.info("Successfully subtracted minutes from the input time");
+ return newTime.format(outputFormatter);🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| } catch (DateTimeParseException e) { | ||
| String errorMessage = "Invalid date/time format. Please use the format: " + inputFormatString + ". Error: " + e.getMessage(); | ||
| logger.warn(errorMessage); | ||
| setErrorMessage(errorMessage); | ||
| return null; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| package com.testsigma.addons.ios; | ||
|
|
||
| import com.testsigma.sdk.IOSAction; | ||
| import com.testsigma.sdk.ApplicationType; | ||
| import com.testsigma.sdk.annotation.Action; | ||
| import com.testsigma.sdk.annotation.TestData; | ||
| import com.testsigma.sdk.annotation.RunTimeData; | ||
| import lombok.Data; | ||
| import org.apache.commons.lang3.exception.ExceptionUtils; | ||
| import org.openqa.selenium.NoSuchElementException; | ||
| import java.time.LocalDateTime; | ||
| import java.time.LocalTime; | ||
| import java.time.format.DateTimeFormatter; | ||
| import java.time.format.DateTimeParseException; | ||
|
|
||
| @Data | ||
| @Action(actionText = "Add minute minutes to the input-datetime with input-datetime-format, convert to output-datetime-format format, and store it in a runtime variable variable-name", | ||
| description = "Adds specified minutes to a given input datetime, converts the resulting datetime to a specified date-time format, and stores it in a runtime variable", | ||
| applicationType = ApplicationType.IOS, | ||
| useCustomScreenshot = false) | ||
| public class AddMinutesToDateTime extends IOSAction { | ||
|
|
||
| @TestData(reference = "input-datetime") | ||
| private com.testsigma.sdk.TestData dateTime; | ||
| @TestData(reference = "input-datetime-format") | ||
| private com.testsigma.sdk.TestData inputFormat; | ||
| @TestData(reference = "output-datetime-format") | ||
| private com.testsigma.sdk.TestData outputFormat; | ||
| @TestData(reference = "minute") | ||
| private com.testsigma.sdk.TestData minutesToAdd; | ||
|
|
||
| @TestData(reference = "variable-name", isRuntimeVariable = true) | ||
| private com.testsigma.sdk.TestData variableName; | ||
|
|
||
| @RunTimeData | ||
| private com.testsigma.sdk.RunTimeData runTimeData; | ||
|
|
||
| @Override | ||
| public com.testsigma.sdk.Result execute() throws NoSuchElementException { | ||
| logger.info("Initiating execution"); | ||
| com.testsigma.sdk.Result result = com.testsigma.sdk.Result.SUCCESS; | ||
| String dateTimeString = dateTime.getValue().toString(); | ||
| String inputFormatString = inputFormat.getValue().toString(); | ||
| String outputFormatString = outputFormat.getValue().toString(); | ||
| String minutesToAddString = minutesToAdd.getValue().toString(); | ||
| String variableNameString = variableName.getValue().toString(); | ||
|
|
||
| try { | ||
| int minutes = Integer.parseInt(minutesToAddString); | ||
|
|
||
| if (minutes < 0) { | ||
| result = com.testsigma.sdk.Result.FAILED; | ||
| setErrorMessage("The 'minute' value must be a non-negative integer."); | ||
| logger.warn("Invalid input: 'minute' value is negative."); | ||
| return result; | ||
| } | ||
|
|
||
| String newDateTime = addMinutesToDateTime(dateTimeString, inputFormatString, outputFormatString, minutes); | ||
|
|
||
| logger.info("New date-time value: " + newDateTime); | ||
|
|
||
| if (newDateTime != null) { | ||
| runTimeData.setValue(newDateTime); | ||
| runTimeData.setKey(variableNameString); | ||
| logger.info("Final value stored in variable '" + variableNameString + "' with value '" + newDateTime + "'"); | ||
| setSuccessMessage(String.format("Added %s minutes to %s and stored the output in '%s' format. %s : %s", | ||
| minutes, dateTimeString, outputFormatString, variableNameString, newDateTime)); | ||
| } else { | ||
| result = com.testsigma.sdk.Result.FAILED; | ||
| setErrorMessage("Failed to add minutes. Please check the input datetime, input datetime format, and output datetime format."); | ||
| } | ||
|
|
||
| } catch (NumberFormatException e) { | ||
| result = com.testsigma.sdk.Result.FAILED; | ||
| setErrorMessage("Invalid number format for 'minutes': " + minutesToAddString); | ||
| logger.warn("NumberFormatException: " + e); | ||
|
|
||
| } catch (Exception e) { | ||
| result = com.testsigma.sdk.Result.FAILED; | ||
| setErrorMessage("An unexpected error occurred: " + ExceptionUtils.getMessage(e)); | ||
| logger.warn("Exception during execution: " + ExceptionUtils.getStackTrace(e)); | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| public String addMinutesToDateTime(String dateTimeString, String inputFormatString, String outputFormatString, int minutesToAdd) { | ||
| try { | ||
| DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern(inputFormatString); | ||
|
|
||
| if (inputFormatString.contains("HH") || inputFormatString.contains("mm") || inputFormatString.contains("ss")) { | ||
| DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputFormatString); | ||
| LocalTime time = LocalTime.parse(dateTimeString, inputFormatter); | ||
| LocalTime newTime = time.plusMinutes(minutesToAdd); | ||
| logger.info("Successfully added minutes to the input time"); | ||
|
|
||
| return newTime.format(outputFormatter); | ||
|
|
||
| } else { | ||
|
|
||
| DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputFormatString); | ||
| LocalDateTime dateTime = LocalDateTime.parse(dateTimeString, inputFormatter); | ||
|
|
||
| LocalDateTime newDateTime = dateTime.plusMinutes(minutesToAdd); | ||
|
Comment on lines
+90
to
+103
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. 🧩 Analysis chain🏁 Script executed: git ls-files | grep -i "AddMinutesToDateTime"Repository: testsigmahq/testsigma-addons Length of output: 1887 🏁 Script executed: cat -n add_minutes_to_the_specific_date_time_and_store_the_output_in_specific_format/src/main/java/com/testsigma/addons/ios/AddMinutesToDateTime.javaRepository: testsigmahq/testsigma-addons Length of output: 1887 🏁 Script executed: # Verify LocalTime.parse() behavior with different format patterns
python3 << 'EOF'
# LocalTime.parse() in Java only accepts time-only formats
# Let's document what would happen with different patterns:
formats_to_test = [
"HH:mm", # time only - should work with LocalTime
"HH:mm:ss", # time only - should work with LocalTime
"yyyy-MM-dd HH:mm", # has date - SHOULD FAIL with LocalTime
"yyyy-MM-dd", # date only - should fail with LocalTime
"MM-dd HH:mm:ss", # mixed - SHOULD FAIL with LocalTime
]
print("Format patterns analysis:")
print("-" * 60)
for fmt in formats_to_test:
has_date_pattern = any(p in fmt for p in ["yyyy", "MM", "dd", "yy", "D", "d"])
has_time_pattern = any(p in fmt for p in ["HH", "mm", "ss", "h"])
print(f"\nFormat: {fmt}")
print(f" Has date pattern: {has_date_pattern}")
print(f" Has time pattern: {has_time_pattern}")
print(f" Safe for LocalTime.parse(): {has_time_pattern and not has_date_pattern}")
EOFRepository: testsigmahq/testsigma-addons Length of output: 1887 Line 90's condition is insufficient for routing time-only vs. datetime parsing. The check only verifies presence of time tokens (HH, mm, ss) but ignores date tokens (yyyy, MM, dd, etc.). Formats like 🤖 Prompt for AI Agents |
||
| logger.info("Successfully added minutes to the input datetime"); | ||
|
|
||
| return newDateTime.format(outputFormatter); | ||
| } | ||
|
|
||
| } catch (DateTimeParseException e) { | ||
| String errorMessage = "Invalid date/time format. Please use the format: " + inputFormatString + ". Error: " + e.getMessage(); | ||
| logger.warn(errorMessage); | ||
| setErrorMessage(errorMessage); | ||
| return null; | ||
| } | ||
| } | ||
| } | ||
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.
🧩 Analysis chain
🏁 Script executed:
Repository: testsigmahq/testsigma-addons
Length of output: 1887
🏁 Script executed:
Repository: testsigmahq/testsigma-addons
Length of output: 1887
🏁 Script executed:
Repository: testsigmahq/testsigma-addons
Length of output: 1887
🏁 Script executed:
Repository: testsigmahq/testsigma-addons
Length of output: 1887
🏁 Script executed:
Repository: testsigmahq/testsigma-addons
Length of output: 1887
🌐 Web query:
DateTimeFormatter.ofPattern IllegalArgumentException exceptions Java 8💡 Result:
DateTimeFormatter.ofPattern(String pattern) in Java 8 throws IllegalArgumentException when the provided pattern string is invalid. This occurs during the parsing of the pattern by DateTimeFormatterBuilder.appendPattern(String), which internally processes the pattern letters and symbols. Common causes include: - Unknown or unsupported pattern letters (e.g., invalid characters not defined in the pattern letter table like 'O' in some contexts, though primarily seen in SimpleDateFormat; for DateTimeFormatter, any undefined letter). - Invalid counts of pattern letters for specific fields (e.g., more than allowed letters for certain zone formats, as noted: "Any other count of letters throws IllegalArgumentException"). - Malformed patterns, such as incorrect use of quotes for literals or adjacent fields causing parsing conflicts (e.g., patterns with digit literals after numeric fields like "yyyyMM'00'" may fail due to known bugs in Java 8, leading to parse exceptions but related to pattern validation). Valid pattern letters (A-Z, a-z) are reserved, and the count determines the format (e.g., 1-3 for short text, 4 for full). Use single quotes ' for literals (escape with ''). Examples of invalid patterns triggering IllegalArgumentException: - Undefined letters. - Excessive letters for fields like zone ID (e.g., more than 2 for ID). Note: Some parsing issues (e.g., adjacent digits) result in DateTimeParseException at runtime, not IllegalArgumentException at formatter creation. Known Java 8 bugs (JDK-8031085, JDK-8032491) affect certain patterns but were fixed in Java 9. To avoid: Consult the official pattern documentation and test patterns. Use DateTimeFormatterBuilder for complex cases.
Citations:
Catch
IllegalArgumentExceptionfrom invalid pattern strings alongsideDateTimeParseException.DateTimeFormatter.ofPattern()throwsIllegalArgumentExceptionwhen the pattern string is invalid (undefined letters, excessive letter counts, malformed syntax). This exception occurs before any parsing attempt and is currently uncaught, allowing invalid patterns to propagate unhandled instead of being caught and logged with actionable messaging.Proposed fix
🤖 Prompt for AI Agents