com.palantir.baseline:baseline-error-proneã®æ¤æ»ã®summaryãå訳ãã¦ããã¾ãã part 1ã§ããéä¸ã§åå°½ããã®ã§ãã¨ããããããã¾ã§ã§ä¸ãã¦ããã¾ãã
com/palantir/baseline/errorprone/AfterburnerJavaIncompatibility
AfterburnerModule㯠jdk16+ ã§ã¯ äºææ§ããªããã©ã³ã¿ã¤ã ã«å¤±æãå¼ãèµ·ããã¾ããAfterburnerModuleãåãé¤ãããã©ã³ã¿ã¤ã ãèæ
®ãã¦conjure-java-jackson-optimizations
ã® ObjectMapperOptimizations.createModules() ã«ç½®ãæãã¦ãã ããã
com/palantir/baseline/errorprone/AssertNoArgs
è¨³è æ³¨:
palantirã®ã©ã¤ãã©ãªã®è©±ã®ãããªã®ã§é£ã°ã
com/palantir/baseline/errorprone/AutoCloseableMustBeClosed
ã³ã³ã¹ãã©ã¯ã¿ãã¡ã½ããã§ AutoCloseable
ãè¿ããªãã é©åã«å¼ã³åºãå
ã§ãªã½ã¼ã¹ãã¯ãã¼ãºãããã¨ãä¿è¨¼ããããã«ã@MustBeClosed
ãã¢ããã¼ã·ã§ã³ã¨ãã¦ä»ä¸ãã¹ãã§ãã
è¨³è æ³¨: error proneæ¬ä½ã«ãMustBeClosedChecker ã¨ããã®ãããããããè£å©ããããã®ã«ã¼ã«
com/palantir/baseline/errorprone/AvoidNewHashMapInt
HashMap(int)
㨠HashSet(int)
ã®ã³ã³ã¹ãã©ã¯ã¿ã¯ã誤解ãæãã¾ãã
HashMap/HashSetã¯ãä¸ãããããµã¤ãºã® 3/4 ã«éããã¨ããªãµã¤ãºããã¾ãã
代ããã«ãæå¾
ããæåã示ããMaps.newHashMapWithExpectedSize
ã Sets.newHashSetWithExpectedSize
ã使ã£ã¦ãã ããã
ãã詳ããæ
å ±ã¯ãã®ããã¥ã¡ã³ããèªãã§ãã ããã)
com/palantir/baseline/errorprone/BadAssert
- Assert statements should not be used. Asserts are generally enabled in tests but disabled in production, which means code can execute in production that is impossible to test.\nIf you\'re confident that an \'assert\' is required, this check may be suppressed using @SuppressWarnings(\"BadAssert\")
assert statement ã¯ã使ç¨ãã¹ãã§ã¯ããã¾ãããã¢ãµã¼ãã¯ä¸è¬çã«ãã¹ãã§ã¯æå¹ã§ãããæ¬çªã§ã¯ç¡å¹ã§ããã¤ã¾ããtestã§ã¯ä¸å¯è½ãªã³ã¼ãããproductionã§ã¯å®è¡ãããå¯è½æ§ãããã¾ãããããããªããèªä¿¡ãæã£ã¦ãassert
ãå¿
è¦ãªãã°ããã®ãã§ãã¯ã¯ã@SuppressWarnings("BadAssert")
ã§æå¶ãã¦ãè¯ãã§ãããã
è¨³è æ³¨:
assert statementã¯è¨èªä»æ§ã® assert statement
com/palantir/baseline/errorprone/BugCheckerAutoService
- Concrete BugChecker implementations should be annotated
@AutoService(BugChecker.class)
for auto registration with error-prone.
BugCheckerã®å®è£
㯠error-proneã«èªåç»é²ããããã«ã@AutoService(BugChecker.class)
ã§ã¢ããã¼ãããã¦ããã¹ãã§ãã
è¨³è æ³¨:
@AutoService
ãä»ä¸ãããã¨ã§ãannotation processorã«ãã£ã¦ java.util.ServiceLoader
ã«å¿
è¦ãªãã¡ã¤ã«ãèªåçæãã¦ãããã
com/palantir/baseline/errorprone/CardinalityEqualsZero
ã³ã¬ã¯ã·ã§ã³ã®ãµã¤ãºã確ããã代ããã«ãisEmptyã使ã£ã¦ãã ããã
com/palantir/baseline/errorprone/CatchBlockLogException
catchç¯ã®ä¸ã®ãã°ã§ãcatchããä¾å¤ããã°ã«åºåãã¦ãã¾ããã
com/palantir/baseline/errorprone/CatchSpecificity
- Prefer more specific error types than Exception and Throwable. When methods are updated to throw new checked exceptions they expect callers to handle failure types explicitly. Catching broad types defeats the type system. By catching the most specific types possible we leverage existing compiler functionality to detect unreachable code.\nNote: Checked exceptions are only validated by the compiler and can be thrown by non-standard bytecode at runtime, for example when java code calls into groovy or scala generated bytecode a checked exception can be thrown despite not being declared. In these scenarios we recommend suppressing this check using @SuppressWarnings(\"CatchSpecificity\") and a comment describing the reason. Remaining instances can be automatically fixed using ./gradlew compileJava -PerrorProneApply=CatchSpecificity
訳è ã¡ã¢: é·ãã®ã§å¾ã§è¦ã
com/palantir/baseline/errorprone/CollectionStreamForEach
- Collection.forEach is more efficient than Collection.stream().forEach
Collection.forEach
ã¯ãCollection.stream().forEach
ããå¹ççã§ãã
com/palantir/baseline/errorprone/CompileTimeConstantViolatesLiskovSubstitution
- @CompileTimeConstant annotations on method parameters must also be applied to the super method. Similarly, if a superclass or superinterface is annotated, implementations must also be annotated.
ã¡ã½ãã弿°ã® @CompileTimeConstant
ã¢ããã¼ã·ã§ã³ã¯ãã¹ã¼ãã¼ã¡ã½ããã«ãé©ç¨ãããã¹ãã§ãããããã¹ã¼ãã¼ã¯ã©ã¹ãã¹ã¼ãã¼ã¤ã³ã¿ã¼ãã§ã¼ã¹ã«ã¢ããã¼ãããã¦ãããªããå®è£
ã§ãã¢ããã¼ãããã¦ããã¹ãã§ãã
è¨³è æ³¨:
@CompileTimeConstant
㯠error prone annotations ã«å«ã¾ãã¦ããã¢ããã¼ã·ã§ã³ã§ãã
See https://github.com/google/error-prone/blob/3369aaaa3359e8e01465521bd87e599541df4f05/annotations/src/main/java/com/google/errorprone/annotations/CompileTimeConstant.java
com/palantir/baseline/errorprone/ConjureEndpointDeprecatedForRemoval
è¨³è æ³¨:
Conjureã¯ãpalantir ã® ã©ã¤ãã©ãªã®ãããªã®ã§ç¿»è¨³ãã¦ãã¾ããã
com/palantir/baseline/errorprone/ConsistentLoggerName
- Loggers created using getLogger(Class<?>) must be named \'log\'.
getLogger(Class<?>)
ã§ä½ããããã¬ã¼ã¯ãlog
ã¨å½åãã¹ãã§ãã
com/palantir/baseline/errorprone/ConsistentOverrides
åãåã®è¤æ°ã®ãã©ã¡ã¼ã¿ããããªããæ£ãããªãå¤ã®å¤æ°ã¸ã®æç¸ãé¿ããããã«ãã¡ã½ããã®ãªã¼ãã¼ã©ã¤ãã¯ã夿°åã§ãã¹ã¼ãã¼ã¡ã½ããã¨ä¸è´ããã¹ãã§ãã
com/palantir/baseline/errorprone/DangerousCollapseKeysUsage
è¨³è æ³¨:
one.util.streamex.EntryStream
ã®è©±ããããé£ã°ãã
com/palantir/baseline/errorprone/DangerousCompletableFutureUsage
Executor
ãæå®ããªããéåæå¦çã¯è¨±å¯ãã¾ããã
è¨³è æ³¨:
ãã®ã«ã¼ã«ã¯è¯ãã
com/palantir/baseline/errorprone/DangerousIdentityKey
- Key type does not override equals() and hashCode, so comparisons will be done on reference equality only. If neither deduplication nor lookup are needed, consider using a List instead. Otherwise, use IdentityHashMap/Set, or an Iterable/List of pairs.
Keyã®åã¯ãequals
, hashCode
ããªã¼ãã¼ã©ã¤ããã¦ãã¾ããããã®ãããæ¯è¼ã¯åç
§æ¯è¼ã®ã¿è¡ããã¾ããéè¤æé¤ãæ¤ç´¢ãå¿
è¦ãªããªããListã代ããã«ä½¿ããã¨ãæ¤è¨ãã¦ãã ããããã以å¤ã®å ´åã¯ãIdentityHashMap/Setãããã¯ãIterable/Listã®ãã¢ã使ã£ã¦ãã ããã
com/palantir/baseline/errorprone/DangerousJavaDeserialization
ã»ãã¥ãªãã£ã®ããã«ãJavaã®Serializationã®å©ç¨ã¯è¨±å¯ãã¾ããã åç §: https://cwe.mitre.org/data/definitions/502.html
com/palantir/baseline/errorprone/DangerousJsonTypeInfoUsage
ã»ãã¥ãªãã£ã®ããã«ãJacksonã®Type Informationæ©è½ã¯å©ç¨ãã¾ããã åç §: https://github.com/FasterXML/jackson-databind/issues/1599
è¨³è æ³¨:
JsonTypeInfo
ã¢ããã¼ã·ã§ã³ã使ã£ã¦ãJSONã«ããã¯ã©ã¹æ
å ±ãå
ã«ãDeserilizeãããã¨ããã¨
容æã«Remote Code Executionã®èå¼±æ§ãçºçããã使ã£ã¦ã¯ãªããªãã
com/palantir/baseline/errorprone/DangerousParallelStreamUsage
Java streamsã® .parallel()
ã®å©ç¨ã¯ãããããã¾ããã
è¨³è æ³¨:
ãã¶ããForkJoinPoolã®commonPoolã«ä¾åãã¦ã¦ãIOå¦çãããã¨æ»ã¬ãããã¨æãããã
Executor
ã使ãã
com/palantir/baseline/errorprone/DangerousRecordArrayField
- Record type has an array field and hasn\'t overridden equals/hashcode. By default array equality performs reference equality only. Consider using an immutable Collection for the field, using Immutables instead of the record, or overriding equals/hashCode in the record.
é åããã£ã¼ã«ãã«æã¤ã¬ã³ã¼ãåã§ãeqauls/hashCodeããªã¼ãã¼ã©ã¤ããã¦ãã¾ãããããã©ã«ãã§ã¯ãé åã®å夿§ã¯ãåç §ã®å夿§ã®ã¿å®è¡ããã¾ãã ãã£ã¼ã«ãã«ä¸å¤ã®ã³ã¬ã¯ã·ã§ã³ã使ããã¨ãæ¤è¨ããããrecordã使ããã«ãImmutablesã使ãããeqauls/hashCode ããªã¼ãã¼ã©ã¤ããã¦ãã ããã
è¨³è æ³¨:
ãã¶ããImmutablesã¨ããã®ã¯ãã
com/palantir/baseline/errorprone/DangerousStringInternUsage
String.intern()
ã¯ä½¿ãã¹ãã§ã¯ãªãã
è¨³è æ³¨:
é·ãã®ã§ã翻訳ãã¦ãªããåæãä¹ãã¦ããã
# åæ Should not use String.intern(). Java string intern is complex and unpredictable. In most cases intern performs worse than pure-java implementations such as Guava Interners (https://guava.dev/releases/27.0.1-jre/api/docs/com/google/common/collect/Interners.html). If you are confident that String.intern is the correct tool, please make sure you fully understand the consequences. From https://shipilev.net/jvm/anatomy-quarks/10-string-intern/ > For OpenJDK, String.intern() is the gateway to native JVM String table, and it comes with > caveats: throughput, memory footprint, pause time problems will await the users. It is very > easy to underestimate the impact of these caveats. Hand-rolled deduplicators/interners are > working much more reliably, because they are working on Java side, are just the regular Java > objects, generally better sized/resized, and also can be thrown away completely when not needed > anymore. GC-assisted String deduplication does alleviate things even more. > In almost every project we were taking care of, removing String.intern() from the hotpaths, > or optionally replacing it with a handrolled deduplicator, was the very profitable performance > optimization. Do not use String.intern() without thinking very hard about it, okay?
com/palantir/baseline/errorprone/DangerousThreadPoolExecutorUsage
ç´æ¥ThreadPoolExecutorã使ããã¨ã¯è¨±å¯ãã¾ããã
è¨³è æ³¨:
ThreadPoolExecutorãç´æ¥ä½¿ãã¨ããããããã°ãçºçãããããã®ã§é¿ããã¹ãã ããã®ã¡ãã»ã¼ã¸ã«ãæ¸ãã¦ããããcorePoolSize != maxPoolSizeã«ãã¦ãunboundã大ããwork queueãæã£ãæã«çºçããã ãã®å ´åãcorePoolSizeãã大ãããªããªãã
æ¥æ¬èªã ã¨ãããªã©ã«æ¸ããã¦ããå 容ã§ãã åç §: https://ik.am/entries/443
com/palantir/baseline/errorprone/DangerousThrowableMessageSafeArg
- It is unsafe to create a SafeArg of Throwable.getMessage, SafeLoggable.getLogMessage may be used.
è¨³è æ³¨: palantir å é¨ã®è©±ã®ãããªã®ã§é£ã°ãã https://github.com/palantir/safe-logging ã¨ãããã©ã¤ãã©ãªãããã£ã½ãã
com/palantir/baseline/errorprone/DefaultLocale
ããã©ã«ããã±ã¼ã«ã®æé»çå©ç¨ãJVMã®å®è¡éã§æåãå¤ããå¯è½æ§ãããã¾ãã
com/palantir/baseline/errorprone/DeprecatedGuavaObjects
æ¨æºã©ã¤ãã©ãªã® java.util.Objects
ã®Utility㯠Guavaã® com.google.common.base.Objects
ãç½®ãæãã¾ãã
com/palantir/baseline/errorprone/DnsLookup
new InetSocketAddress(host, port)
ã®å¼ã³åºãã¯ãDNS lookupãçºçãããã§ã«è§£æ±ºããã¦ããã®ã§ãDNSã®å¤æ´ã«è¿½å¾ãããã¨ã妨ãã¾ãã
å ãã¦ãããã¯ãæ¬è³ªçã«ãããã¯ã¼ã¯ãªã¯ã¨ã¹ãã§ããç°å¢ã«ãã£ã¦ã¯ãå¼åºã®ã³ã¹ãã¯ãäºæ³ããã大å¹
ã«é«ããªãå ´åãããã¾ãã
ãã®ãã§ãã¯ã¯å©è¨ãç®çã¨ãã¦ãã¾ããç¹å®ã®ã±ã¼ã¹ã§ã¯ãæå¶ãã¦ãè¯ãã§ããã大ä½ã¯ããããã§ãã¾ããã
com/palantir/baseline/errorprone/ExecutorSubmitRunnableFutureIgnored
ExecutorService.submit
ãã è£è¶³ãã¦ããªãä¾å¤ããuncaught exception handlerã«ãã£ã¦ãã°åºåããã¾ããããªããªãè¿å´ããã futureãfailuresã®ããã«è¦ããã¦ãããã¨ãä»®å®ãã¦ããããã§ããè¿å´ããã futureãç¡è¦ããã¨ãã¯ãExecutorService.execute
ã使ãã®ã好ã¾ããã§ãã失æã¯è¨é²ãããã®ã§ã
è¨³è æ³¨:
ExecutorService.submitã ã¨ãThreadã®uncaught exception handlerã«ãã£ã¦å¦çãããªãï¼ ã¡ãã£ã¨å¥ã§ç¢ºããããã
com/palantir/baseline/errorprone/ExtendsErrorOrThrowable
- Class should not extend Error or Throwable directly. While allowed by java it can lead to surprising behaviour if users end up catching Error or Throwable.
ã¯ã©ã¹ã¯ãç´æ¥ErrorãThrowableãç¶æ¿ãã¹ãã§ã¯ãªããJavaã§ã¯è¨±å¯ããã¦ãã¾ããããããã¦ã¼ã¶ãErrorãThrowableããã£ãããããªããããã¯äºæããªãæåãå¼ãèµ·ããå¯è½æ§ãããã¾ãã
com/palantir/baseline/errorprone/FilterOutputStreamSlowMultibyteWrite
void write(byte[], int, int)
ããªã¼ãã¼ã©ã¤ããã¦ãã ããããããªãã°ããã®OutputStreamã¸ã®ãã«ããã¤ãã®æ¸ãè¾¼ã¿ã¯é
ãå¯è½æ§ãããã¾ãã
è¨³è æ³¨:
ã©ãããã°ãããããããå®éã«ãªã¼ãã¼ã©ã¤ãããã¦ãããã¤è¦ããæ°ãããã 䏿¦ã¹ãããã
com/palantir/baseline/errorprone/FinalClass
ã³ã³ã¹ãã©ã¯ã¿ã®å ¨ã¦ãprivateãªããã¯ã©ã¹ã¯ finalã§å®£è¨ãã¹ãã§ããUtilityã¯ã©ã¹ãã¤ã¾ããã¯ã©ã¹ã®å ¨ã¦ã®ã¡ã½ããããã£ã¼ã«ãstaticã§ãprivateã§ä½ãããªã弿°ãæããªãã³ã³ã¹ãã©ã¯ã¿ã https://github.com/palantir/gradle-baseline/tree/develop/docs/best-practices/java-coding-guidelines#private-constructors
com/palantir/baseline/errorprone/ForbidJavaxParameterType
javax.ws.rsã®ãããªå¤ãjavaxã®åã使ã£ã¦ãããªãã¸ã§ã¯ãã ããæ°ããjakartaã®åãå¿ è¦ã¨ãã¦ããã¡ã½ããã«æå®ããã¨ãå®è¡æã¨ã©ã¼ã«ãªãã¾ãã ãã®ãã§ãã¯ã¯ãåã®ãªãObjectãåã«åãä¸è¬çãªãããã®ã¡ã½ããã«ããªããé©åã«åãæå®ãã¦ãããã¨ã確ããã¦ãã¾ãã ãã®ãã§ãã¯ã«ã¯ auto-fixã¯ããã¾ãããæåã§ç´ãå¿ è¦ãããã¾ãã
com/palantir/baseline/errorprone/GradleCacheableArgumentProvider
gradle argument providersã ã©ã ãå¼ã§å®è£ ãããã¨ã¯ç¦æ¢ãã¾ãã
com/palantir/baseline/errorprone/GradleCacheableTaskAction
gradle task actions (doFirst, doLast) ã ã©ã ãå¼ã§å®è£ ãããã¨ã¯ç¦æ¢ãã¾ãã
com/palantir/baseline/errorprone/GradleProviderToString
Providerã®toStringãå¼ãã§ããä¸ã«å ¥ã£ã¦ããå¤ã¯ã¬ã³ããªã³ã°ãããªãã
com/palantir/baseline/errorprone/GuavaPreconditionsMessageFormat
Guava Preconditions.checkX() ã® ã¡ã½ããã¯ãprint-f ã®ãã©ã¼ãããã使ãã¹ãã§ãã
com/palantir/baseline/errorprone/IllegalSafeLoggingArgument
è¨³è æ³¨:
safe-loggingã®è©±ãªã®ã§ãé£ã°ãã
com/palantir/baseline/errorprone/ImmutableMapDuplicateKeyStrategy
- ImmutableMap.Builder.build() has non-obvious behavior, throwing on duplicate keys. Please use \'buildKeepingLast()\' or \'buildOrThrow()\' for more obvious behavior.
ImmutableMap.Builder.build()
ã¯èªæã§ã¯ãªãæåãæã¡ãéè¤ãããã¼ã®å ´åä¾å¤ãæãã¾ãã
ããèªæãªæåã®ããã« buildKeepingLast()
ã buildOrThrow()
ã使ã£ã¦ãã ããã
com/palantir/baseline/errorprone/ImmutablesBuilderMissingInitialization
Immutables builder ã®å¿ è¦ãªå ¨ã¦ã®ãã£ã¼ã«ãã¯ãåæåãããã¹ãã§ãã
com/palantir/baseline/errorprone/ImmutablesReferenceEquality
å¤ã®å夿§ã®ä»£ããã«ãåç §ã®å夿§ã«ãã£ã¦ãImmutablesã®å¤ã®æ¯è¼ããã¦ããã
com/palantir/baseline/errorprone/ImmutablesStyle
è¨³è æ³¨: ã©ããImmutables使ã£ã¦ãªãããé¢åããããªã£ãã®ã§é£ã°ã
çµãã
æ®ãã¯å¥ã®è¨äºã§ã»ã»ã»