-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Issue #1032 Use null safe method for bytes to hex string conversion #1069
Conversation
@zilm13 If you are ok with static imports, I will use the same thing throughout all files wherever I make changes |
de84dd4
to
b971cf0
Compare
b971cf0
to
1c831ee
Compare
To avoid making this a huge PR, I have added changes only to the implementation and once this is merged I will make another for test, Is that cool? Also, I have made changes only at those place where we are printing or logging some message ( i.e, logs, some println, exception or error messages etc ). Have avoided changing toString() functions. I can do that with subsequent PRs with making sure that my new change don't avoid throwing an error that should been thrown otherwise. |
We need to change them too. It's object logging that fails in case of one field is null. You'd better move file by file, so I could check that it's done for this file but as you already did it for many files, just add it to toString methods too and I will check everything together. From first view you did it ok, but it needs more attention with branch checkout before merge, so it's better to finish it for toString methods too or any other methods that are called from logging. |
1c831ee
to
654e0ab
Compare
@zilm13 ready for review. I hope none of the toString() methods are being used for anything except logging, otherwise this might break things. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but few changes required according to comments.
- change it here too: https://github.com/ethereum/ethereumj/blob/develop/ethereumj-core/src/main/java/org/ethereum/sync/SyncPool.java#L340
- +4 lines in
VM.dumpLine()
used in dumpLogger, everything ending withgetNoLeadZeroesData()
in input
And it would be good!
@@ -45,6 +44,7 @@ | |||
import static org.ethereum.util.ByteUtil.toHexString; | |||
import static org.ethereum.vm.VMUtils.saveProgramTraceFile; | |||
import static org.ethereum.vm.VMUtils.zipAndEncode; | |||
import static org.ethereum.util.ByteUtil.toHexString; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicate import
@@ -40,6 +40,7 @@ | |||
import java.util.concurrent.locks.ReentrantReadWriteLock; | |||
|
|||
import static java.lang.System.arraycopy; | |||
import static org.ethereum.util.ByteUtil.toHexString; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused org.spongycastle.util.encoders.Hex
import above
@@ -25,6 +25,8 @@ | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
|
|||
import static org.ethereum.util.ByteUtil.toHexString; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused org.spongycastle.util.encoders.Hex
import above
@@ -25,6 +25,8 @@ | |||
|
|||
import java.math.BigInteger; | |||
|
|||
import static org.ethereum.util.ByteUtil.toHexString; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused org.spongycastle.util.encoders.Hex
import above
@@ -25,6 +25,8 @@ | |||
|
|||
import java.math.BigInteger; | |||
|
|||
import static org.ethereum.util.ByteUtil.toHexString; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused org.spongycastle.util.encoders.Hex
import above
@@ -101,7 +97,7 @@ public String toString() { | |||
long currTime = System.currentTimeMillis() / 1000; | |||
|
|||
String out = String.format("[PongMessage] \n token: %s \n expires in %d seconds \n %s\n", | |||
Hex.toHexString(token), (expires - currTime), super.toString()); | |||
ByteUtil.toHexString(token), (expires - currTime), super.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct spacing, please
Hex.toHexString(lastHash.getData()), | ||
Hex.toHexString(coinbase.getLast20Bytes()), | ||
ByteUtil.toHexString(callValue.getNoLeadZeroesData()), | ||
data == null ? "" : ByteUtil.toHexString(data), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you've changed it to null-safe, condition checking is no more required
This commit replaces use of `org.spongycastle.util.encoders.Hex.toHexString()` (Not null safe) with `org.ethereum.util.ByteUtil.toHexString()` (null safe) while logging and in all toString() methods. This covers only logging in the implementation(`/src/main`) and doesn't cover any logging in tests(`/src/tests`) Issue ethereum#1032
`hint` and `contract` are only being used in logs. Changing the toHexString function for them should not break anything. Issue ethereum#1032
Removed unused imports and other changes as asked for Issue ethereum#1032
More conversions Issue ethereum#1032
654e0ab
to
a5f4e74
Compare
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is weird. The comment is not changed at all, but GitHub is showing it to be changed.
@@ -225,7 +225,7 @@ public void onPendingTransactionUpdate(TransactionReceipt txReceipt, PendingTran | |||
} | |||
|
|||
public void requestFreeEther(byte[] addressBytes) { | |||
String address = "0x" + Hex.toHexString(addressBytes); | |||
String address = "0x" + toHexString(addressBytes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
address
is used only for logging, so no harm changing it here.
import static org.apache.commons.lang3.ArrayUtils.isEmpty; | ||
import static org.apache.commons.lang3.ArrayUtils.nullToEmpty; | ||
import static org.ethereum.util.ByteUtil.toHexString; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because duplicate imports
@@ -1255,7 +1255,7 @@ else if (oldValue != null && newValue.isZero()) { | |||
program.setHReturn(hReturn); | |||
|
|||
if (logger.isInfoEnabled()) | |||
hint = "data: " + Hex.toHexString(hReturn) | |||
hint = "data: " + toHexString(hReturn) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hint
is used only in logs
@@ -1401,7 +1401,7 @@ private void dumpLine(OpCode op, long gasBefore, long gasCost, long memWords, Pr | |||
} | |||
|
|||
int level = program.getCallDeep(); | |||
String contract = Hex.toHexString(program.getOwnerAddress().getLast20Bytes()); | |||
String contract = toHexString(program.getOwnerAddress().getLast20Bytes()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contract
is used only in logs
Thank you! |
This is does not include all such cases
Fix for #1032
@zilm13 Since I would be using the same approach throughout all such cases, i just wanted to get this validated if this approach looks good to you.