Skip to content
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

GeneralCodingRules to detect usages of old time and date classes #1384

Open
Bukama opened this issue Nov 27, 2024 · 0 comments
Open

GeneralCodingRules to detect usages of old time and date classes #1384

Bukama opened this issue Nov 27, 2024 · 0 comments

Comments

@Bukama
Copy link

Bukama commented Nov 27, 2024

Over at Bluesky Gunnar Morling "cried" about the fact that still many people use old date and time classes and asked if there are any build time checkers to detect that. I answered that my team at work and I wrote ArchUnit rules for that, which lead @rweisleder to ask if I could provide them to the ArchUnit's GeneralCodingRules .

The rules we wrote at my work

 */
public class DateTimeRules {

  static final String JAVATIME_REASON = "since Java 8 and JavaEE 7 java.time-API should be used.";

  @ArchTest
  public static final ArchRule NO_JAVA_SQL_DATE = noClasses().should().dependOnClassesThat()
      .haveFullyQualifiedName("java.sql.Date").because(JAVATIME_REASON);

  @ArchTest
  public static final ArchRule NO_JAVA_SQL_TIME = noClasses().should().dependOnClassesThat()
      .haveFullyQualifiedName("java.sql.Time").because(JAVATIME_REASON);

  @ArchTest
  public static final ArchRule NO_JAVA_SQL_TIMESTAMP = noClasses().should().dependOnClassesThat()
      .haveFullyQualifiedName("java.sql.Timestamp").because(JAVATIME_REASON);

  @ArchTest
  public static final ArchRule NO_JAVA_UTIL_CALENDAR = noClasses().should().dependOnClassesThat()
      .haveFullyQualifiedName("java.util.Calendar").because(JAVATIME_REASON);

  @ArchTest
  public static final ArchRule NO_JAVA_UTIL_DATE = noClasses().should().dependOnClassesThat()
      .haveFullyQualifiedName("java.util.Date").because(JAVATIME_REASON);

}

I'll give it a try to create a PR to add them to ArchUnit.

P.S. For everyone who's wondering why those classes are not deprecated: Brian Goetz mentioned that they most probably will never be annotated with @Deprecated cause of the global usage in almost infinite APIs all over the Java universe, e.g. see this mailing list entry.

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

No branches or pull requests

1 participant