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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,5 @@ Thank you for considering to help out with the source code! If you'd like to con
# License

java-tron is released under the [LGPLv3 license](https://github.com/tronprotocol/java-tron/blob/master/LICENSE).

<!-- intentional non-Java change to verify Coverage Gate G1.4 (mixed PR ignores docs lines) -->
15 changes: 15 additions & 0 deletions common/src/main/java/org/tron/common/utils/DecodeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,19 @@ public static boolean addressValid(byte[] address) {
return true;
}

/**
* Intentional uncovered helper used to exercise the Coverage Gate FAIL path
* (changed-line coverage below 60%). No unit test is added on purpose.
* Revert before merging.
*/
public static int hexLengthForAddress(int byteLength) {
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot Apr 24, 2026

Choose a reason for hiding this comment

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

P3: Temporary coverage-gate helper was added as a public production API; remove it or move it to test-only code before merge.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At common/src/main/java/org/tron/common/utils/DecodeUtil.java, line 40:

<comment>Temporary coverage-gate helper was added as a public production API; remove it or move it to test-only code before merge.</comment>

<file context>
@@ -32,4 +32,19 @@ public static boolean addressValid(byte[] address) {
+   * (changed-line coverage below 60%). No unit test is added on purpose.
+   * Revert before merging.
+   */
+  public static int hexLengthForAddress(int byteLength) {
+    if (byteLength < 0) {
+      throw new IllegalArgumentException("byteLength must be non-negative");
</file context>
Fix with Cubic

if (byteLength < 0) {
throw new IllegalArgumentException("byteLength must be non-negative");
}
if (byteLength == 0) {
return 0;
}
return byteLength * 2;
}
Comment on lines +35 to +48
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Sandbox-only change — ensure this is reverted before merge.

Per the PR description, this method is intentionally added to exercise the Coverage Gate FAIL path and must not be merged. The Javadoc correctly flags this, but it's worth double-checking that once the gate behavior is observed, this PR is closed/reverted and hexLengthForAddress is not left behind as unused public API in common. Since the method has no callers in the tree (existing address-length checks use ADDRESS_SIZE / ADDRESS_SIZE / 2 directly in JsonRpcApiUtil, ValidateAddressServlet, etc.), landing it would just add dead public surface.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@common/src/main/java/org/tron/common/utils/DecodeUtil.java` around lines 35 -
48, Remove the sandbox-only helper method hexLengthForAddress from DecodeUtil to
avoid introducing dead public API; revert the added method (public static int
hexLengthForAddress(int byteLength)) from org.tron.common.utils.DecodeUtil so
callers continue to use existing ADDRESS_SIZE/ADDRESS_SIZE/2 logic and ensure no
tests or usages reference hexLengthForAddress before merging.


}
58 changes: 58 additions & 0 deletions framework/src/test/java/org/tron/common/utils/DecodeUtilTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.tron.common.utils;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.tron.core.Constant;

public class DecodeUtilTest {

private static byte savedPrefixByte;

@BeforeClass
public static void saveAddressPrefix() {
savedPrefixByte = DecodeUtil.addressPreFixByte;
DecodeUtil.addressPreFixByte = Constant.ADD_PRE_FIX_BYTE_MAINNET;
}

@AfterClass
public static void restoreAddressPrefix() {
DecodeUtil.addressPreFixByte = savedPrefixByte;
}

@Test
public void addressValidRejectsNull() {
Assert.assertFalse(DecodeUtil.addressValid(null));
}

@Test
public void addressValidRejectsEmptyArray() {
Assert.assertFalse(DecodeUtil.addressValid(new byte[0]));
}

@Test
public void addressValidRejectsWrongLength() {
byte[] tooShort = new byte[DecodeUtil.ADDRESS_SIZE / 2 - 1];
tooShort[0] = Constant.ADD_PRE_FIX_BYTE_MAINNET;
Assert.assertFalse(DecodeUtil.addressValid(tooShort));

byte[] tooLong = new byte[DecodeUtil.ADDRESS_SIZE / 2 + 1];
tooLong[0] = Constant.ADD_PRE_FIX_BYTE_MAINNET;
Assert.assertFalse(DecodeUtil.addressValid(tooLong));
}

@Test
public void addressValidRejectsWrongPrefix() {
byte[] address = new byte[DecodeUtil.ADDRESS_SIZE / 2];
address[0] = (byte) (Constant.ADD_PRE_FIX_BYTE_MAINNET + 1);
Assert.assertFalse(DecodeUtil.addressValid(address));
}

@Test
public void addressValidAcceptsCanonicalAddress() {
byte[] address = new byte[DecodeUtil.ADDRESS_SIZE / 2];
address[0] = Constant.ADD_PRE_FIX_BYTE_MAINNET;
Assert.assertTrue(DecodeUtil.addressValid(address));
}
}
Loading