Skip to content

[java] Update rule AvoidCalendarDateCreation#3395

Merged
oowekyala merged 4 commits into
pmd:pmd/7.0.xfrom
adangel:pmd7-update-AvoidCalendarDateCreation
Aug 7, 2021
Merged

[java] Update rule AvoidCalendarDateCreation#3395
oowekyala merged 4 commits into
pmd:pmd/7.0.xfrom
adangel:pmd7-update-AvoidCalendarDateCreation

Conversation

@adangel

@adangel adangel commented Jul 9, 2021

Copy link
Copy Markdown
Member

@adangel adangel added this to the 7.0.0 milestone Jul 9, 2021
@ghost

ghost commented Jul 9, 2021

Copy link
Copy Markdown
2 Messages
📖 Compared to pmd/7.0.x:
This changeset changes 0 violations,
introduces 4 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report
📖 Compared to master:
This changeset changes 30195 violations,
introduces 32705 new violations, 3 new errors and 0 new configuration errors,
removes 143880 violations, 8 errors and 3 configuration errors.
Full report
Compared to pmd/7.0.x:
This changeset changes 0 violations,
introduces 10 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report
Compared to master:
This changeset changes 30201 violations,
introduces 32705 new violations, 3 new errors and 0 new configuration errors,
removes 143874 violations, 8 errors and 3 configuration errors.
Full report
Compared to pmd/7.0.x:
This changeset changes 0 violations,
introduces 22 new violations, 0 new errors and 0 new configuration errors,
removes 852 violations, 0 errors and 0 configuration errors.
Full report
Compared to master:
This changeset changes 76 violations,
introduces 705 new violations, 3 new errors and 0 new configuration errors,
removes 5984 violations, 8 errors and 3 configuration errors.
Full report

Generated by 🚫 Danger

@adangel

adangel commented Jul 10, 2021

Copy link
Copy Markdown
Member Author

Maybe the following is a false-positive, wdyt?

parsedDate = calb.establish(calendar).getTime();

(https://github.com/openjdk/jdk/blob/jdk-11%2B28/src/java.base/share/classes/java/text/SimpleDateFormat.java#L1559)

calb is a CalendarBuilder, calb.establish() returns a java.util.Calendar on which getTime() is called. But we should probably only report this, if the calendar instance is created here....

return new Date(getTimeInMillis());

(https://github.com/openjdk/jdk/blob/jdk-11%2B28/src/java.base/share/classes/java/util/Calendar.java#L1785)

We should not report this. It calls getTimeInMillis() on "this" (which happens to be here java.util.Calendar...).

c = new Calendar.Builder().setTimeZone(TimeZone.getTimeZone("GMT"))
                    .setDate(year, month - 1, day).build();
...
denyAfterDate = c.getTime();

(https://github.com/openjdk/jdk/blob/jdk-11%2B28/src/java.base/share/classes/sun/security/util/DisabledAlgorithmConstraints.java#L636)

That's also a false-positive: The calendar "c" is not created via getInstance, but via a builder with a specific date set....

Date sentDate = new GregorianCalendar(2004, 1, 1).getTime();

(https://github.com/spring-projects/spring-framework/blob/v5.0.6.RELEASE/spring-context-support/src/test/java/org/springframework/mail/javamail/JavaMailSenderTests.java#L73)

This creates a new calendar instance with a specific date set via constructor... That's also a false-positive

Update: All of these have been fixed ✔️

@oowekyala oowekyala left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@oowekyala oowekyala self-assigned this Aug 7, 2021
@oowekyala oowekyala merged commit 06674ee into pmd:pmd/7.0.x Aug 7, 2021
@adangel adangel deleted the pmd7-update-AvoidCalendarDateCreation branch August 19, 2021 08:29
@adangel adangel mentioned this pull request Jan 23, 2023
55 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants