Repository: LFDT-web3j/web3j (2026-04-03T13:14:39Z)

Issue:
IDE inspction warning:: Raw use of parameterized class 'EthLog.LogResult'
Is there anyway to fix it?
 
 
- Web3j 5.0.2
- Java: JDK 21
- Operating System: windows 11


# _Bug_title_
_A clear and concise description of what the issue is._

## Steps To Reproduce
_Describe the exact steps or scenario to reproduce the issue._

### Expected behavior
_A clear and concise description of what you expected to happen._

### Actual behavior
_A description of the actual behavior occurring._

## Environment
_Describe the environment in which the issue occurs_
- Web3j 5.0.2
- Java: JDK 21
- Operating System: windows 11


## Additional context
_Add any other context about the problem here._
- Logs
- Sample code and/or code snippets
- Unit/integration tests to highlight the issue
- [etherscan](https://etherscan.io/) references  





Discussion:
Hi @formingform, I'm interested in looking into this. Could you provide the Actual behavior and Steps to Reproduce? Once I can replicate the issue, I'd love to help submit a PR




Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9e5aeafd6c..01ca7d6979 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,7 +7,8 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
 
 ### Bug Fixes
 
-*
+* Replace raw usage of `EthLog.LogResult` with parameterized type to improve type safety (#2252)
+(https://github.com/LFDT-web3j/web3j/pull/2254)
 
 ### Features
 
diff --git a/core/src/main/java/org/web3j/protocol/core/filters/BlockFilter.java b/core/src/main/java/org/web3j/protocol/core/filters/BlockFilter.java
index c411b63bb9..c3ead7a546 100644
--- a/core/src/main/java/org/web3j/protocol/core/filters/BlockFilter.java
+++ b/core/src/main/java/org/web3j/protocol/core/filters/BlockFilter.java
@@ -35,8 +35,8 @@ protected EthFilter sendRequest() throws IOException {
     }
 
     @Override
-    protected void process(List<EthLog.LogResult> logResults) {
-        for (EthLog.LogResult logResult : logResults) {
+    protected void process(List<EthLog.LogResult<?>> logResults) {
+        for (EthLog.LogResult<?> logResult : logResults) {
             if (logResult instanceof EthLog.Hash) {
                 String blockHash = ((EthLog.Hash) logResult).get();
                 callback.onEvent(blockHash);
diff --git a/core/src/main/java/org/web3j/protocol/core/filters/BlocksFilter.java b/core/src/main/java/org/web3j/protocol/core/filters/BlocksFilter.java
index 6fc51bc1da..ac4a6481c3 100644
--- a/core/src/main/java/org/web3j/protocol/core/filters/BlocksFilter.java
+++ b/core/src/main/java/org/web3j/protocol/core/filters/BlocksFilter.java
@@ -37,10 +37,10 @@ protected EthFilter sendRequest() throws IOException {
     }
 
     @Override
-    protected void process(List<LogResult> logResults) {
+    protected void process(List<LogResult<?>> logResults) {
         List<String> blockHashes = new ArrayList<>(logResults.size());
 
-        for (EthLog.LogResult logResult : logResults) {
+        for (EthLog.LogResult<?> logResult : logResults) {
             if (!(logResult instanceof EthLog.Hash)) {
                 throw new FilterException(
                         "Unexpected result type: " + logResult.get() + ", required Hash");
diff --git a/core/src/main/java/org/web3j/protocol/core/filters/Filter.java b/core/src/main/java/org/web3j/protocol/core/filters/Filter.java
index d083caf7a3..1ceb2790e7 100644
--- a/core/src/main/java/org/web3j/protocol/core/filters/Filter.java
+++ b/core/src/main/java/org/web3j/protocol/core/filters/Filter.java
@@ -157,7 +157,7 @@ private void pollFilter(EthFilter ethFilter) {
 
     protected abstract EthFilter sendRequest() throws IOException;
 
-    protected abstract void process(List<EthLog.LogResult> logResults);
+    protected abstract void process(List<EthLog.LogResult<?>> logResults);
 
     private void reinstallFilter() {
         log.warn(
diff --git a/core/src/main/java/org/web3j/protocol/core/filters/LogFilter.java b/core/src/main/java/org/web3j/protocol/core/filters/LogFilter.java
index 417e7ce2fc..550cd2d0e6 100644
--- a/core/src/main/java/org/web3j/protocol/core/filters/LogFilter.java
+++ b/core/src/main/java/org/web3j/protocol/core/filters/LogFilter.java
@@ -42,8 +42,8 @@ protected EthFilter sendRequest() throws IOException {
     }
 
     @Override
-    protected void process(List<EthLog.LogResult> logResults) {
-        for (EthLog.LogResult logResult : logResults) {
+    protected void process(List<EthLog.LogResult<?>> logResults) {
+        for (EthLog.LogResult<?> logResult : logResults) {
             if (logResult instanceof EthLog.LogObject) {
                 Log log = ((EthLog.LogObject) logResult).get();
                 callback.onEvent(log);
diff --git a/core/src/main/java/org/web3j/protocol/core/filters/LogsFilter.java b/core/src/main/java/org/web3j/protocol/core/filters/LogsFilter.java
index b75ca88b03..4620dffb34 100644
--- a/core/src/main/java/org/web3j/protocol/core/filters/LogsFilter.java
+++ b/core/src/main/java/org/web3j/protocol/core/filters/LogsFilter.java
@@ -44,10 +44,10 @@ protected EthFilter sendRequest() throws IOException {
     }
 
     @Override
-    protected void process(List<LogResult> logResults) {
+    protected void process(List<LogResult<?>> logResults) {
         List<Log> logs = new ArrayList<>(logResults.size());
 
-        for (EthLog.LogResult logResult : logResults) {
+        for (EthLog.LogResult<?> logResult : logResults) {
             if (!(logResult instanceof EthLog.LogObject)) {
                 throw new FilterException(
                         "Unexpected result type: " + logResult.get() + " required LogObject");
diff --git a/core/src/main/java/org/web3j/protocol/core/filters/PendingTransactionFilter.java b/core/src/main/java/org/web3j/protocol/core/filters/PendingTransactionFilter.java
index 8dcccbb2f5..33ba5d1f97 100644
--- a/core/src/main/java/org/web3j/protocol/core/filters/PendingTransactionFilter.java
+++ b/core/src/main/java/org/web3j/protocol/core/filters/PendingTransactionFilter.java
@@ -35,8 +35,8 @@ protected EthFilter sendRequest() throws IOException {
     }
 
     @Override
-    protected void process(List<EthLog.LogResult> logResults) {
-        for (EthLog.LogResult logResult : logResults) {
+    protected void process(List<EthLog.LogResult<?>> logResults) {
+        for (EthLog.LogResult<?> logResult : logResults) {
             if (logResult instanceof EthLog.Hash) {
                 String transactionHash = ((EthLog.Hash) logResult).get();
                 callback.onEvent(transactionHash);
diff --git a/core/src/main/java/org/web3j/protocol/core/filters/PendingTransactionsFilter.java b/core/src/main/java/org/web3j/protocol/core/filters/PendingTransactionsFilter.java
index bde8028e8e..6f40572672 100644
--- a/core/src/main/java/org/web3j/protocol/core/filters/PendingTransactionsFilter.java
+++ b/core/src/main/java/org/web3j/protocol/core/filters/PendingTransactionsFilter.java
@@ -36,10 +36,10 @@ protected EthFilter sendRequest() throws IOException {
     }
 
     @Override
-    protected void process(List<EthLog.LogResult> logResults) {
+    protected void process(List<EthLog.LogResult<?>> logResults) {
         List<String> logs = new ArrayList<>(logResults.size());
 
-        for (EthLog.LogResult logResult : logResults) {
+        for (EthLog.LogResult<?> logResult : logResults) {
             if (!(logResult instanceof EthLog.Hash)) {
                 throw new FilterException(
                         "Unexpected result type: " + logResult.get() + ", required Hash");
diff --git a/core/src/main/java/org/web3j/protocol/core/methods/response/EthLog.java b/core/src/main/java/org/web3j/protocol/core/methods/response/EthLog.java
index c80ca90d67..ce32af7b89 100644
--- a/core/src/main/java/org/web3j/protocol/core/methods/response/EthLog.java
+++ b/core/src/main/java/org/web3j/protocol/core/methods/response/EthLog.java
@@ -39,15 +39,15 @@
  * <p>See <a href="https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getfilterchanges">docs</a> for
  * further details.
  */
-public class EthLog extends Response<List<EthLog.LogResult>> {
+public class EthLog extends Response<List<EthLog.LogResult<?>>> {
 
     @Override
     @JsonDeserialize(using = LogResultDeserialiser.class)
-    public void setResult(List<LogResult> result) {
+    public void setResult(List<LogResult<?>> result) {
         super.setResult(result);
     }
 
-    public List<LogResult> getLogs() {
+    public List<LogResult<?>> getLogs() {
         return getResult();
     }
 
@@ -127,16 +127,16 @@ public int hashCode() {
         }
     }
 
-    public static class LogResultDeserialiser extends JsonDeserializer<List<LogResult>> {
+    public static class LogResultDeserialiser extends JsonDeserializer<List<LogResult<?>>> {
 
         private ObjectReader objectReader = ObjectMapperFactory.getObjectReader();
 
         @Override
-        public List<LogResult> deserialize(
+        public List<LogResult<?>> deserialize(
                 JsonParser jsonParser, DeserializationContext deserializationContext)
                 throws IOException {
 
-            List<LogResult> logResults = new ArrayList<>();
+            List<LogResult<?>> logResults = new ArrayList<>();
             JsonToken nextToken = jsonParser.nextToken();
 
             if (nextToken == JsonToken.START_OBJECT) {


Test patch:
diff --git a/core/src/test/java/org/web3j/protocol/core/filters/FilterTester.java b/core/src/test/java/org/web3j/protocol/core/filters/FilterTester.java
index c36138589e..e3af213284 100644
--- a/core/src/test/java/org/web3j/protocol/core/filters/FilterTester.java
+++ b/core/src/test/java/org/web3j/protocol/core/filters/FilterTester.java
@@ -111,12 +111,13 @@ <T> void runTest(EthLog ethLog, Flowable<T> flowable) throws Exception {
         assertTrue(subscription.isDisposed());
     }
 
-    List createExpected(EthLog ethLog) {
-        List<EthLog.LogResult> logResults = ethLog.getLogs();
+    @SuppressWarnings("unchecked")
+    <T> List<T> createExpected(EthLog ethLog) {
+        List<EthLog.LogResult<?>> logResults = ethLog.getLogs();
         if (logResults.isEmpty()) {
             fail("Results cannot be empty");
         }
 
-        return ethLog.getLogs().stream().map(EthLog.LogResult::get).toList();
+        return (List<T>) ethLog.getLogs().stream().map(EthLog.LogResult::get).toList();
     }
 }
diff --git a/integration-tests/src/test/java/org/web3j/protocol/core/CoreIT.java b/integration-tests/src/test/java/org/web3j/protocol/core/CoreIT.java
index e664cb9ed0..fde91df6c3 100644
--- a/integration-tests/src/test/java/org/web3j/protocol/core/CoreIT.java
+++ b/integration-tests/src/test/java/org/web3j/protocol/core/CoreIT.java
@@ -441,7 +441,7 @@ public void testFiltersByFilterId() throws Exception {
 
         // eth_getFilterLogs
         EthLog ethFilterLogs = web3j.ethGetFilterLogs(filterId).send();
-        List<EthLog.LogResult> filterLogs = ethFilterLogs.getLogs();
+        List<EthLog.LogResult<?>> filterLogs = ethFilterLogs.getLogs();
         assertFalse(filterLogs.isEmpty());
 
         // eth_getFilterChanges - nothing will have changed in this interval
@@ -480,7 +480,7 @@ public void testEthGetLogs() throws Exception {
         ethFilter.addSingleTopic(config.encodedEvent());
 
         EthLog ethLog = web3j.ethGetLogs(ethFilter).send();
-        List<EthLog.LogResult> logs = ethLog.getLogs();
+        List<EthLog.LogResult<?>> logs = ethLog.getLogs();
         assertFalse(logs.isEmpty());
     }
 
diff --git a/integration-tests/src/test/java/org/web3j/protocol/scenarios/EventFilterIT.java b/integration-tests/src/test/java/org/web3j/protocol/scenarios/EventFilterIT.java
index 096657c856..76559b192c 100644
--- a/integration-tests/src/test/java/org/web3j/protocol/scenarios/EventFilterIT.java
+++ b/integration-tests/src/test/java/org/web3j/protocol/scenarios/EventFilterIT.java
@@ -81,11 +81,11 @@ public void testEventFilter() throws Exception {
                         new Uint256(BigInteger.valueOf(1)), new Uint256(BigInteger.valueOf(1)))));
 
         // finally check it shows up in the event filter
-        List<EthLog.LogResult> filterLogs = createFilterForEvent(encodedEventSignature);
+        List<EthLog.LogResult<?>> filterLogs = createFilterForEvent(encodedEventSignature);
         assertFalse(filterLogs.isEmpty());
     }
 
-    private List<EthLog.LogResult> createFilterForEvent(String encodedEventSignature)
+    private List<EthLog.LogResult<?>> createFilterForEvent(String encodedEventSignature)
             throws Exception {
         EthFilter ethFilter =
                 new EthFilter(