Admin can't assign user to 'On-Call Role Schedule'

Description

Steps:

  1. login as admin user (Admin role/ Admin group)

  2. open 'User and Groups' (http://localhost:8980/opennms/admin/userGroupView/index.jsp)

  3. open 'Configure On-Call Roles'

  4. created a Role 'new role'

  5. click on that role 

  6. in On-Call Role Schedule table click on any button to assign user on it

  7. In 'Edit Schedule Entry' (http://localhost:8980/opennms/admin/userGroupView/roles) select any user and set up any date.

  8. click Save

Expected:
User will be assigned on this date

 

Actual:

 

1) on 'Edit Schedule Entry' user sees empty alert notification message. 

2) after click on Save button UI sends

Request URL: http://localhost:8980/opennms/admin/userGroupView/rolesRequest Method: POST Status Code: 500 Server Error operation=saveEntry&role=OnCall&schedIndex=-1&timeIndex=-1&_csrf=6bf706b5-718f-4bc6-a863-fb570363aed9&roleUser=admin& startDate=29&startMonth=9&startYear=2022&startHour=12&startMinute=00&startAmOrPm=AM& endDate=29&endMonth=9&endYear=2022&endHour=12&endMinute=00&endAmOrPm=AM&save=

 

startAmOrPm=AM
endAmOrPm=AM 

that causes backend issue:

javax.servlet.ServletException: javax.servlet.ServletException: Unable to parse date: Unparseable date: "9-29-2022 12:00 AM" ... Caused by: javax.servlet.ServletException: Unable to parse date: Unparseable date: "9-29-2022 12:00 AM" ... Caused by: java.text.ParseException: Unparseable date: "9-29-2022 12:00 AM" at java.text.DateFormat.parse(DateFormat.java:395) ~[?:?] at org.opennms.web.admin.roles.AdminRoleServlet$SaveEntryAction.getDateParameters(AdminRoleServlet.java:240) ~[?:?] at org.opennms.web.admin.roles.AdminRoleServlet$SaveEntryAction.execute(AdminRoleServlet.java:191) ~[?:?] at org.opennms.web.admin.roles.AdminRoleServlet.doIt(AdminRoleServlet.java:309) ~[?:?] at org.opennms.web.admin.roles.AdminRoleServlet.doPost(AdminRoleServlet.java:351) ~[?:?]

in that class org/opennms/web/admin/roles/AdminRoleServlet.java at 241th row:
 

return new SimpleDateFormat("M-d-yyyy h:m a").parse(buf.toString());

Root cause?

it's not clear what triggered this issue.

From what I see:

SimpleDateFormat parser = new SimpleDateFormat("M-d-yyyy h:m a"); // "M-d-yyyy h:m a" System.out.println(parser.format(new Date())); // 9-8-2022 4:23 p.m.

Since we have AM / PM from UI data, it couldn't be parsed by this pattern because it expects a.m. / p.m. 

But this issue could be solved by adding `Locale.US` (it works on local env)

SimpleDateFormat parser2 = new SimpleDateFormat("M-d-yyyy h:m a", Locale.US); // "M-d-yyyy h:m a" System.out.println(parser2.format(new Date())); // 9-8-2022 4:23 PM

Environment

Local env : opennms-31.0.0-SNAPSHOT Default locale : en_CA

Acceptance / Success Criteria

None

Attachments

1
  • 08 Sep 2022, 09:04 PM

Lucidchart Diagrams

Activity

Show:

Jeff Gehlbach November 8, 2022 at 4:18 PM

and I agree that this is sufficiently low risk to pull into 31.0.0 even though it didn't make the cut. We have merging to do anyway, so it's no extra work.

Alberto November 8, 2022 at 2:44 PM

merged to 31.x

Alberto November 8, 2022 at 12:26 AM
Edited

The issue is whenever we use SimpleDateFormat without specifying a locale will use the default locale. In my case the default iocale is EN_CA (English Canada) and this causes parsing exceptions.

From the documentation SimpleDateFormat is Locale sensitive. And parsing a formatted date using SimpleDateFormat without specifying an especific Locale will become an issue in different parts of OpenNMS.

I will create a new Jira to ensure we use at least Locale.ROOT (that seems to be the implemented in a few places already in OpenNMS) in all the SimpleDateFormat instantiations.

Jeff Gehlbach September 28, 2022 at 1:52 PM

Big if reproducible.

Fixed

Details

Assignee

Reporter

HB Grooming Date

HB Backlog Status

Sprint

Fix versions

Affects versions

Priority

PagerDuty

Created September 8, 2022 at 9:03 PM
Updated November 8, 2022 at 4:18 PM
Resolved November 8, 2022 at 2:44 PM