Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.tron.common.math.StrictMathWrapper;
Expand Down Expand Up @@ -166,7 +167,7 @@ public boolean validate() throws ContractValidateException {
}

if (dynamicStore.getAllowSameTokenName() != 0) {
String name = assetIssueContract.getName().toStringUtf8().toLowerCase();
String name = assetIssueContract.getName().toStringUtf8().toLowerCase(Locale.ROOT);
if (("trx").equals(name)) {
throw new ContractValidateException("assetName can't be trx");
}
Expand Down
26 changes: 26 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import org.gradle.nativeplatform.platform.internal.Architectures
import org.gradle.internal.os.OperatingSystem

plugins {
id 'net.ltgt.errorprone' version '5.0.0' apply false
}

allprojects {
version = "1.0.0"
apply plugin: "java-library"
ext {
springVersion = "5.3.39"
errorproneVersion = "2.42.0"
}
}
def arch = System.getProperty("os.arch").toLowerCase()
Expand Down Expand Up @@ -107,6 +113,26 @@ subprojects {
testImplementation "org.mockito:mockito-core:4.11.0"
testImplementation "org.mockito:mockito-inline:4.11.0"
}
if (project.name != 'protocol' && project.name != 'errorprone'
&& javaVersion.isJava11Compatible()) {
apply plugin: 'net.ltgt.errorprone'
dependencies {
errorprone "com.google.errorprone:error_prone_core:${errorproneVersion}"
errorprone rootProject.project(':errorprone')
}
tasks.withType(JavaCompile).configureEach {
options.errorprone {
enabled = true
disableWarningsInGeneratedCode = true
disableAllChecks = true
excludedPaths = '.*/generated/.*'
errorproneArgs.addAll([
'-Xep:StringCaseLocaleUsage:ERROR',
'-Xep:StringCaseLocaleUsageMethodRef:ERROR',
])
}
}
}

task sourcesJar(type: Jar, dependsOn: classes) {
classifier = "sources"
Expand Down
5 changes: 3 additions & 2 deletions chainbase/src/main/java/org/tron/core/db/TronDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.protobuf.InvalidProtocolBufferException;
import java.nio.file.Paths;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.PostConstruct;
Expand Down Expand Up @@ -37,10 +38,10 @@ protected TronDatabase(String dbName) {
this.dbName = dbName;

if ("LEVELDB".equals(CommonParameter.getInstance().getStorage()
.getDbEngine().toUpperCase())) {
.getDbEngine().toUpperCase(Locale.ROOT))) {
dbSource = new LevelDbDataSourceImpl(StorageUtils.getOutputDirectoryByDbName(dbName), dbName);
} else if ("ROCKSDB".equals(CommonParameter.getInstance()
.getStorage().getDbEngine().toUpperCase())) {
.getStorage().getDbEngine().toUpperCase(Locale.ROOT))) {
String parentName = Paths.get(StorageUtils.getOutputDirectoryByDbName(dbName),
CommonParameter.getInstance().getStorage().getDbDirectory()).toString();
dbSource = new RocksDbDataSourceImpl(parentName, dbName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Paths;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -38,7 +39,7 @@
@Slf4j(topic = "DB")
public abstract class TronStoreWithRevoking<T extends ProtoCapsule> implements ITronChainBase<T> {

@Getter // only for unit test
@Getter
protected IRevokingDB revokingDB;
private TypeToken<T> token = new TypeToken<T>(getClass()) {
};
Expand All @@ -54,10 +55,10 @@ public abstract class TronStoreWithRevoking<T extends ProtoCapsule> implements I

protected TronStoreWithRevoking(String dbName) {
String dbEngine = CommonParameter.getInstance().getStorage().getDbEngine();
if ("LEVELDB".equals(dbEngine.toUpperCase())) {
if ("LEVELDB".equals(dbEngine.toUpperCase(Locale.ROOT))) {
this.db = new LevelDB(
new LevelDbDataSourceImpl(StorageUtils.getOutputDirectoryByDbName(dbName), dbName));
} else if ("ROCKSDB".equals(dbEngine.toUpperCase())) {
} else if ("ROCKSDB".equals(dbEngine.toUpperCase(Locale.ROOT))) {
String parentPath = Paths
.get(StorageUtils.getOutputDirectoryByDbName(dbName), CommonParameter
.getInstance().getStorage().getDbDirectory()).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
Expand Down Expand Up @@ -102,10 +103,10 @@ public TxCacheDB(String name, RecentTransactionStore recentTransactionStore,
this.recentTransactionStore = recentTransactionStore;
this.dynamicPropertiesStore = dynamicPropertiesStore;
String dbEngine = CommonParameter.getInstance().getStorage().getDbEngine();
if ("LEVELDB".equals(dbEngine.toUpperCase())) {
if ("LEVELDB".equals(dbEngine.toUpperCase(Locale.ROOT))) {
this.persistentStore = new LevelDB(
new LevelDbDataSourceImpl(StorageUtils.getOutputDirectoryByDbName(name), name));
} else if ("ROCKSDB".equals(dbEngine.toUpperCase())) {
} else if ("ROCKSDB".equals(dbEngine.toUpperCase(Locale.ROOT))) {
String parentPath = Paths
.get(StorageUtils.getOutputDirectoryByDbName(name), CommonParameter
.getInstance().getStorage().getDbDirectory()).toString();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.tron.core.store;

import com.google.protobuf.ByteString;
import java.util.Locale;
import java.util.Objects;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -21,7 +22,8 @@ public AccountIdIndexStore(@Value("accountid-index") String dbName) {

private static byte[] getLowerCaseAccountId(byte[] bsAccountId) {
return ByteString
.copyFromUtf8(ByteString.copyFrom(bsAccountId).toStringUtf8().toLowerCase()).toByteArray();
.copyFromUtf8(ByteString.copyFrom(bsAccountId).toStringUtf8().toLowerCase(Locale.ROOT))
.toByteArray();
}

public void put(AccountCapsule accountCapsule) {
Expand Down Expand Up @@ -54,4 +56,4 @@ public boolean has(byte[] key) {
return !ArrayUtils.isEmpty(value);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ public class DynamicPropertiesStore extends TronStoreWithRevoking<BytesCapsule>

private static final byte[] ALLOW_TVM_OSAKA = "ALLOW_TVM_OSAKA".getBytes();

private static final byte[] TURKISH_KEY_MIGRATION_DONE =
"TURKISH_KEY_MIGRATION_DONE".getBytes();

@Autowired
private DynamicPropertiesStore(@Value("properties") String dbName) {
super(dbName);
Expand Down Expand Up @@ -2993,6 +2996,18 @@ public void saveAllowTvmOsaka(long value) {
this.put(ALLOW_TVM_OSAKA, new BytesCapsule(ByteArray.fromLong(value)));
}

public void saveTurkishKeyMigrationDone(long num) {
this.put(TURKISH_KEY_MIGRATION_DONE,
new BytesCapsule(ByteArray.fromLong(num)));
}

public long getTurkishKeyMigrationDone() {
return Optional.ofNullable(getUnchecked(TURKISH_KEY_MIGRATION_DONE))
.map(BytesCapsule::getData)
.map(ByteArray::toLong)
.orElse(0L);
}

private static class DynamicResourceProperties {

private static final byte[] ONE_DAY_NET_LIMIT = "ONE_DAY_NET_LIMIT".getBytes();
Expand Down
5 changes: 3 additions & 2 deletions common/src/main/java/org/tron/common/args/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.google.protobuf.ByteString;
import java.io.Serializable;
import java.util.Locale;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.tron.common.utils.ByteArray;
Expand Down Expand Up @@ -120,7 +121,7 @@ public boolean isAccountType(final String accountType) {
return false;
}

switch (accountType.toUpperCase()) {
switch (accountType.toUpperCase(Locale.ROOT)) {
case ACCOUNT_TYPE_NORMAL:
case ACCOUNT_TYPE_ASSETISSUE:
case ACCOUNT_TYPE_CONTRACT:
Expand All @@ -138,7 +139,7 @@ public AccountType getAccountTypeByString(final String accountType) {
throw new IllegalArgumentException("Account type error: Not a Normal/AssetIssue/Contract");
}

switch (accountType.toUpperCase()) {
switch (accountType.toUpperCase(Locale.ROOT)) {
case ACCOUNT_TYPE_NORMAL:
return AccountType.Normal;
case ACCOUNT_TYPE_ASSETISSUE:
Expand Down
5 changes: 3 additions & 2 deletions common/src/main/java/org/tron/common/runtime/vm/DataWord.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.fasterxml.jackson.annotation.JsonValue;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.util.Locale;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.util.encoders.Hex;
import org.tron.common.utils.ByteArray;
Expand Down Expand Up @@ -121,7 +122,7 @@ public static boolean isZero(byte[] data) {

public static String shortHex(byte[] data) {
byte[] bytes = ByteUtil.stripLeadingZeroes(data);
String hexValue = Hex.toHexString(bytes).toUpperCase();
String hexValue = Hex.toHexString(bytes).toUpperCase(Locale.ROOT);
return "0x" + hexValue.replaceFirst("^0+(?!$)", "");
}

Expand Down Expand Up @@ -451,7 +452,7 @@ public String toPrefixString() {
}

public String shortHex() {
String hexValue = Hex.toHexString(getNoLeadZeroesData()).toUpperCase();
String hexValue = Hex.toHexString(getNoLeadZeroesData()).toUpperCase(Locale.ROOT);
return "0x" + hexValue.replaceFirst("^0+(?!$)", "");
}

Expand Down
13 changes: 13 additions & 0 deletions errorprone/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
if (!JavaVersion.current().isJava11Compatible()) {
// ErrorProne core requires JDK 11+; skip this module on JDK 8
tasks.withType(JavaCompile).configureEach { enabled = false }
tasks.withType(Jar).configureEach { enabled = false }
} else {
dependencies {
compileOnly "com.google.errorprone:error_prone_annotations:${errorproneVersion}"
compileOnly "com.google.errorprone:error_prone_check_api:${errorproneVersion}"
compileOnly "com.google.errorprone:error_prone_core:${errorproneVersion}"
compileOnly "com.google.auto.service:auto-service:1.1.1"
annotationProcessor "com.google.auto.service:auto-service:1.1.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package errorprone;

import com.google.auto.service.AutoService;
import com.google.errorprone.BugPattern;
import com.google.errorprone.VisitorState;
import com.google.errorprone.bugpatterns.BugChecker;
import com.google.errorprone.matchers.Description;
import com.google.errorprone.util.ASTHelpers;
import com.sun.source.tree.MemberReferenceTree;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Type;

/**
* Flags method references {@code String::toLowerCase} and {@code String::toUpperCase}
* that resolve to the no-arg overload (which uses {@code Locale.getDefault()}).
*
* <p>The built-in ErrorProne {@code StringCaseLocaleUsage} checker only catches
* direct method invocations ({@code s.toLowerCase()}), not method references
* ({@code String::toLowerCase}). This checker closes that gap.
*/
@AutoService(BugChecker.class)
@BugPattern(
name = "StringCaseLocaleUsageMethodRef",
summary = "String::toLowerCase and String::toUpperCase method references use "
+ "Locale.getDefault(). Replace with a lambda that specifies Locale.ROOT, "
+ "e.g. s -> s.toLowerCase(Locale.ROOT).",
severity = BugPattern.SeverityLevel.ERROR
)
public class StringCaseLocaleUsageMethodRef extends BugChecker
implements BugChecker.MemberReferenceTreeMatcher {

@Override
public Description matchMemberReference(MemberReferenceTree tree, VisitorState state) {
String name = tree.getName().toString();
if (!"toLowerCase".equals(name) && !"toUpperCase".equals(name)) {
return Description.NO_MATCH;
}
// Verify the qualifier type is java.lang.String
Type qualifierType = ((com.sun.tools.javac.tree.JCTree) tree.getQualifierExpression())
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@halibobo1205,

[SHOULD] Avoid casting directly to com.sun.tools.javac.tree.JCTree to read the internal .type field. ErrorProne already wraps this in ASTHelpers.getType():

Type qualifierType = ASTHelpers.getType(tree.getQualifierExpression());

Benefits:

  • Removes a hard dependency on the JDK-internal com.sun.tools.javac.tree.JCTree (requires --add-exports on JDK 9+ and is more likely to break across JDK versions).
  • Stays consistent with the ASTHelpers.getSymbol(tree) style already used a few lines below.
  • Easier to maintain across future ErrorProne upgrades.

The remaining com.sun.tools.javac.code.Symbol / Type imports still belong here (that's the standard BugChecker SDK), but dropping the explicit JCTree cast is a clear win.

.type;
if (qualifierType == null) {
return Description.NO_MATCH;
}
if (!state.getTypes().isSameType(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@halibobo1205,

[NIT] The idiomatic ErrorProne way to compare types is via ASTHelpers:

if (!ASTHelpers.isSameType(qualifierType, state.getSymtab().stringType, state)) {
  return Description.NO_MATCH;
}

Or, using the standard supplier for an even shorter form:

import static com.google.errorprone.suppliers.Suppliers.STRING_TYPE;
...
if (!ASTHelpers.isSameType(qualifierType, STRING_TYPE.get(state), state)) { ... }

Functionally identical, but matches the convention used by ErrorProne's own built-in checkers — easier for future maintainers to recognize.

qualifierType, state.getSymtab().stringType)) {
return Description.NO_MATCH;
}
// Only flag the no-arg overload; the Locale-taking overload is safe
Symbol sym = ASTHelpers.getSymbol(tree);
if (sym instanceof Symbol.MethodSymbol
&& ((Symbol.MethodSymbol) sym).getParameters().isEmpty()) {
return describeMatch(tree);
}
return Description.NO_MATCH;
}
}
11 changes: 6 additions & 5 deletions framework/src/main/java/org/tron/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
Expand Down Expand Up @@ -3880,14 +3881,14 @@ private int getShieldedTRC20LogType(TransactionInfo.Log log, byte[] contractAddr
for (String topic : topicsList) {
byte[] topicHash = Hash.sha3(ByteArray.fromString(topic));
if (Arrays.equals(topicsBytes, topicHash)) {
if (topic.toLowerCase().contains("mint")) {
if (topic.toLowerCase(Locale.ROOT).contains("mint")) {
Comment thread
halibobo1205 marked this conversation as resolved.
return 1;
} else if (topic.toLowerCase().contains("transfer")) {
} else if (topic.toLowerCase(Locale.ROOT).contains("transfer")) {
return 2;
} else if (topic.toLowerCase().contains("burn")) {
if (topic.toLowerCase().contains("leaf")) {
} else if (topic.toLowerCase(Locale.ROOT).contains("burn")) {
if (topic.toLowerCase(Locale.ROOT).contains("leaf")) {
return 3;
} else if (topic.toLowerCase().contains("token")) {
} else if (topic.toLowerCase(Locale.ROOT).contains("token")) {
return 4;
}
}
Expand Down
7 changes: 4 additions & 3 deletions framework/src/main/java/org/tron/core/config/args/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -892,7 +893,7 @@ public static void applyConfigParams(
PARAMETER.disabledApiList =
config.hasPath(ConfigKey.NODE_DISABLED_API_LIST)
? config.getStringList(ConfigKey.NODE_DISABLED_API_LIST)
.stream().map(String::toLowerCase).collect(Collectors.toList())
.stream().map(s -> s.toLowerCase(Locale.ROOT)).collect(Collectors.toList())
: Collections.emptyList();

if (config.hasPath(ConfigKey.NODE_SHUTDOWN_BLOCK_TIME)) {
Expand Down Expand Up @@ -1770,7 +1771,7 @@ public static void printHelp(JCommander jCommander) {
Map<String, String[]> groupOptionListMap = Args.getOptionGroup();
for (Map.Entry<String, String[]> entry : groupOptionListMap.entrySet()) {
String group = entry.getKey();
helpStr.append(String.format("%n%s OPTIONS:%n", group.toUpperCase()));
helpStr.append(String.format("%n%s OPTIONS:%n", group.toUpperCase(Locale.ROOT)));
int optionMaxLength = Arrays.stream(entry.getValue()).mapToInt(p -> {
ParameterDescription tmpParameterDescription = stringParameterDescriptionMap.get(p);
if (tmpParameterDescription == null) {
Expand Down Expand Up @@ -1810,7 +1811,7 @@ public static String upperFirst(String name) {
if (name.length() <= 1) {
return name;
}
name = name.substring(0, 1).toUpperCase() + name.substring(1);
name = name.substring(0, 1).toUpperCase(Locale.ROOT) + name.substring(1);
return name;
}

Expand Down
Loading
Loading