Class GeneralCodingRules


  • public final class GeneralCodingRules
    extends java.lang.Object
    When checking these rules, it is always important to remember that all necessary classes need to be imported. E.g. if ACCESS_STANDARD_STREAMS is checked, which looks for calls on classes assignable to Throwable, it is important to ensure that Exception and RuntimeException are imported as well, otherwise ArchUnit does not know about the inheritance structure of these exceptions, and thus will not consider a call of RuntimeException a violation, since it does not know that RuntimeException extends Throwable. For further information refer to ClassFileImporter.
    • Field Detail

      • NO_CLASSES_SHOULD_ACCESS_STANDARD_STREAMS

        @PublicAPI(usage=ACCESS)
        public static final ArchRule NO_CLASSES_SHOULD_ACCESS_STANDARD_STREAMS
        It is generally good practice to use correct logging instead of writing to the console.
        • Writing to the console cannot be configured in production
        • Writing to the console is synchronized and can lead to bottle necks
        For information about checking this rule, refer to GeneralCodingRules.
      • NO_CLASSES_SHOULD_THROW_GENERIC_EXCEPTIONS

        @PublicAPI(usage=ACCESS)
        public static final ArchRule NO_CLASSES_SHOULD_THROW_GENERIC_EXCEPTIONS
        It is generally good practice to throw specific exceptions like IllegalArgumentException or custom exceptions, instead of throwing generic exceptions like RuntimeException.
        For information about checking this rule, refer to GeneralCodingRules.
      • NO_CLASSES_SHOULD_USE_JAVA_UTIL_LOGGING

        @PublicAPI(usage=ACCESS)
        public static final ArchRule NO_CLASSES_SHOULD_USE_JAVA_UTIL_LOGGING
        Most projects use the more powerful LOG4J or Logback instead of java.util.logging, often hidden behind SLF4J. In this case it's important to ensure consistent use of the agreed logging framework.
        For information about checking this rule, refer to GeneralCodingRules.
      • NO_CLASSES_SHOULD_USE_JODATIME

        @PublicAPI(usage=ACCESS)
        public static final ArchRule NO_CLASSES_SHOULD_USE_JODATIME
        Modern Java projects use the [java.time] API instead of the JodaTime library
        For information about checking this rule, refer to GeneralCodingRules.