Skip to content
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

Inner class wrong definition #601

Open
khaes-kth opened this issue Aug 30, 2021 · 5 comments
Open

Inner class wrong definition #601

khaes-kth opened this issue Aug 30, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@khaes-kth
Copy link
Collaborator

When 2111 fixes are applied on this (commit: eb32eaabd397e7a90eb799ead13eda4d6ea8d1d0), the following change is made:

@@ -526,7 +527,7 @@ public class CollectionTest
 
     }
 
-    static abstract class AbstractFoo
+    abstractstatic abstract class AbstractFoo^M
     {
 
     }

@khaes-kth khaes-kth added the bug Something isn't working label Aug 30, 2021
@algomaster99
Copy link
Member

Hi, @khaes-kth , I followed the link provided but it does not seem relevant as it doesn't even have the class CollectionTest. I am dropping the link for confirmation.

Moreover, I don't understand how S2111 could bring about the above diff. Its processor just replaces the invocation which is not related to what's happening in the above diff. Did you mean some other sonar rule or am I misinterpreting it?

@khaes-kth
Copy link
Collaborator Author

Hi @algomaster99

You're right. The changes in that commit are not related to what Sorald does. But that link specifies the commit id (look at the URL) on which we ran Sorald.

Moreover, I don't understand how S2111 could bring about the above diff.

Exactly, that's the problem. It shouldn't be done, but it is. I guess it has something to do with the Spoon printer.

@algomaster99
Copy link
Member

I ran the repair command, java -jar target/sorald-0.3.1-SNAPSHOT-jar-with-dependencies.jar repair --rule-key S2111 --source CollectionTest.java, on CollectionsTest.java locally but I didn't get the above diff. Instead, I got the following.

diff --git a/CollectionTest.java b/CollectionTest.java
index 91bb78c..74d7115 100644
--- a/CollectionTest.java
+++ b/CollectionTest.java
@@ -415,7 +415,7 @@ public class CollectionTest
         task.setDescription("Complete that other task.");
         task.setTags(tags);
         task.setDateCreated(new Date(System.currentTimeMillis()));
-        task.setBigDecimal(new BigDecimal(564654.234234d));
+        task.setBigDecimal(BigDecimal.valueOf(564654.234234));
         task.setBigInteger(BigInteger.valueOf(System.currentTimeMillis()));
 
         return task;

Could you send me the link to the PR where the above diff was suggested?

@khaes-kth
Copy link
Collaborator Author

I believe the result should be different when you do it for the whole project. This is what get in my terminal when I repair all violations of 2111 in the whole project.

khaes@khaes-desktop:~/phd/projects/sorald/tmp/tmp$ git clone https://github.com/protostuff/protostuff.git
Cloning into 'protostuff'...
remote: Enumerating objects: 25534, done.
remote: Counting objects: 100% (317/317), done.
remote: Compressing objects: 100% (191/191), done.
remote: Total 25534 (delta 135), reused 239 (delta 68), pack-reused 25217
Receiving objects: 100% (25534/25534), 5.26 MiB | 8.09 MiB/s, done.
Resolving deltas: 100% (10565/10565), done.
khaes@khaes-desktop:~/phd/projects/sorald/tmp/tmp$ cd protostuff/
khaes@khaes-desktop:~/phd/projects/sorald/tmp/tmp/protostuff$ git checkout eb32eaabd397e7a90eb799ead13eda4d6ea8d1d0
Note: switching to 'eb32eaabd397e7a90eb799ead13eda4d6ea8d1d0'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at eb32eaab Merge pull request #293 from mirlord/merge-from-coded-input
khaes@khaes-desktop:~/phd/projects/sorald/tmp/tmp/protostuff$ cd ..
khaes@khaes-desktop:~/phd/projects/sorald/tmp/tmp$ java -jar ../sorald.jar repair --source protostuff/ --rule-key 2111
INFO  JavaClasspath initialization
INFO  JavaClasspath initialization (done) | time=28ms
INFO  JavaTestClasspath initialization
INFO  JavaTestClasspath initialization (done) | time=0ms
INFO  Java Main Files AST scan
INFO  405 source files to be analyzed
INFO  395/405 files analyzed, current file: protostuff-runtime/src/test/java/io/protostuff/runtime/NullArrayElementInObjectArrayTest.java
INFO  405/405 source files have been analyzed
INFO  Java Main Files AST scan (done) | time=10588ms
INFO  Java Test Files AST scan
INFO  0 source files to be analyzed
INFO  Java Test Files AST scan (done) | time=1ms
INFO  Java Generated Files AST scan
INFO  0 source files to be analyzed
INFO  Java Generated Files AST scan (done) | time=1ms
INFO  0/0 source files have been analyzed
INFO  0/0 source files have been analyzed
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
-----Number of fixes------
BigDecimalDoubleConstructorProcessor: 32
-----End of report------
khaes@khaes-desktop:~/phd/projects/sorald/tmp/tmp$ cd protostuff/
khaes@khaes-desktop:~/phd/projects/sorald/tmp/tmp/protostuff$ git diff
diff --git a/protostuff-msgpack/src/main/java/io/protostuff/MsgpackGenerator.java b/protostuff-msgpack/src/main/java/io/protostuff/MsgpackGenerator.java
index 0e3abc0e..4627a40c 100644
--- a/protostuff-msgpack/src/main/java/io/protostuff/MsgpackGenerator.java
+++ b/protostuff-msgpack/src/main/java/io/protostuff/MsgpackGenerator.java
@@ -483,7 +483,7 @@ public final class MsgpackGenerator
         @Override
         public BigInteger toBigInteger()
         {
-            return new BigDecimal(value).toBigInteger();
+            return BigDecimal.valueOf(value).toBigInteger();
         }
 
         @Override
diff --git a/protostuff-runtime/src/test/java/io/protostuff/runtime/CollectionTest.java b/protostuff-runtime/src/test/java/io/protostuff/runtime/CollectionTest.java
index 3a645330..f67ba1c3 100644
--- a/protostuff-runtime/src/test/java/io/protostuff/runtime/CollectionTest.java
+++ b/protostuff-runtime/src/test/java/io/protostuff/runtime/CollectionTest.java
@@ -13,6 +13,7 @@
 //========================================================================
 
 package io.protostuff.runtime;
+import static Assert.assertTrue;^M
 
 import static junit.framework.Assert.assertTrue;
 import static org.junit.Assert.assertEquals;
@@ -415,7 +416,7 @@ public class CollectionTest
         task.setDescription("Complete that other task.");
         task.setTags(tags);
         task.setDateCreated(new Date(System.currentTimeMillis()));
-        task.setBigDecimal(new BigDecimal(564654.234234d));
+        task.setBigDecimal(BigDecimal.valueOf(564654.234234));^M
         task.setBigInteger(BigInteger.valueOf(System.currentTimeMillis()));
 
         return task;
@@ -526,7 +527,7 @@ public class CollectionTest
 
     }
 
-    static abstract class AbstractFoo
+    abstractstatic abstract class AbstractFoo^M
     {
 
     }
diff --git a/protostuff-runtime/src/test/java/io/protostuff/runtime/NullArrayElementInObjectArrayTest.java b/protostuff-runtime/src/test/java/io/protostuff/runtime/NullArrayElementInObjectArrayTest.java
index e302db27..b7caf14c 100644
--- a/protostuff-runtime/src/test/java/io/protostuff/runtime/NullArrayElementInObjectArrayTest.java
+++ b/protostuff-runtime/src/test/java/io/protostuff/runtime/NullArrayElementInObjectArrayTest.java
@@ -189,8 +189,8 @@ public abstract class NullArrayElementInObjectArrayTest extends AbstractTest
                 new byte[][] { null, new byte[] { 'a' }, new byte[] { 'b' } },
                 Arrays.asList(new byte[][] { null, new byte[] { 'a' }, new byte[] { 'b' } }),
                 
-                new BigDecimal[] { null, new BigDecimal(1.1d), new BigDecimal(2.2d) },
-                Arrays.asList(new BigDecimal[] { null, new BigDecimal(1.1d), new BigDecimal(2.2d) }),
+                new BigDecimal[] { null, BigDecimal.valueOf(1.1), BigDecimal.valueOf(2.2) },
+                Arrays.asList(new BigDecimal[] { null, BigDecimal.valueOf(1.1), BigDecimal.valueOf(2.2) }),
                 
                 new BigInteger[] { null, new BigInteger("1"), new BigInteger("2") },
                 Arrays.asList(new BigInteger[] { null, new BigInteger("1"), new BigInteger("2") }),
@@ -256,8 +256,8 @@ public abstract class NullArrayElementInObjectArrayTest extends AbstractTest
                 new byte[][] { new byte[] { 'a' }, new byte[] { 'b' }, null },
                 Arrays.asList(new byte[][] { new byte[] { 'a' }, new byte[] { 'b' }, null }),
                 
-                new BigDecimal[] { new BigDecimal(1.1d), new BigDecimal(2.2d), null },
-                Arrays.asList(new BigDecimal[] { new BigDecimal(1.1d), new BigDecimal(2.2d), null }),
+                new BigDecimal[] { BigDecimal.valueOf(1.1), BigDecimal.valueOf(2.2), null },
+                Arrays.asList(new BigDecimal[] { BigDecimal.valueOf(1.1), BigDecimal.valueOf(2.2), null }),
                 
                 new BigInteger[] { new BigInteger("1"), new BigInteger("2"), null },
                 Arrays.asList(new BigInteger[] { new BigInteger("1"), new BigInteger("2"), null }),
@@ -323,8 +323,8 @@ public abstract class NullArrayElementInObjectArrayTest extends AbstractTest
                 new byte[][] { new byte[] { 'a' }, null, new byte[] { 'b' } },
                 Arrays.asList(new byte[][] { new byte[] { 'a' }, null, new byte[] { 'b' } }),
                 
-                new BigDecimal[] { new BigDecimal(1.1d), null, new BigDecimal(2.2d) },
-                Arrays.asList(new BigDecimal[] { new BigDecimal(1.1d), null, new BigDecimal(2.2d) }),
+                new BigDecimal[] { BigDecimal.valueOf(1.1), null, BigDecimal.valueOf(2.2) },
+                Arrays.asList(new BigDecimal[] { BigDecimal.valueOf(1.1), null, BigDecimal.valueOf(2.2) }),
                 
                 new BigInteger[] { new BigInteger("1"), null, new BigInteger("2") },
                 Arrays.asList(new BigInteger[] { new BigInteger("1"), null, new BigInteger("2") }),
@@ -390,8 +390,8 @@ public abstract class NullArrayElementInObjectArrayTest extends AbstractTest
                 new byte[][] { null, new byte[] { 'a' }, new byte[] { 'b' }, null },
                 Arrays.asList(new byte[][] { null, new byte[] { 'a' }, new byte[] { 'b' }, null }),
                 
-                new BigDecimal[] { null, new BigDecimal(1.1d), new BigDecimal(2.2d), null },
-                Arrays.asList(new BigDecimal[] { null, new BigDecimal(1.1d), new BigDecimal(2.2d), null }),
+                new BigDecimal[] { null, BigDecimal.valueOf(1.1), BigDecimal.valueOf(2.2), null },
+                Arrays.asList(new BigDecimal[] { null, BigDecimal.valueOf(1.1), BigDecimal.valueOf(2.2), null }),
                 
                 new BigInteger[] { null, new BigInteger("1"), new BigInteger("2"), null },
                 Arrays.asList(new BigInteger[] { null, new BigInteger("1"), new BigInteger("2"), null }),
@@ -457,8 +457,8 @@ public abstract class NullArrayElementInObjectArrayTest extends AbstractTest
                 new byte[][] { null, new byte[] { 'a' }, null, new byte[] { 'b' }, null },
                 Arrays.asList(new byte[][] { null, new byte[] { 'a' }, null, new byte[] { 'b' }, null }),
                 
-                new BigDecimal[] { null, new BigDecimal(1.1d), null, new BigDecimal(2.2d), null },
-                Arrays.asList(new BigDecimal[] { null, new BigDecimal(1.1d), null, new BigDecimal(2.2d), null }),
+                new BigDecimal[] { null, BigDecimal.valueOf(1.1), null, BigDecimal.valueOf(2.2), null },
+                Arrays.asList(new BigDecimal[] { null, BigDecimal.valueOf(1.1), null, BigDecimal.valueOf(2.2), null }),
                 
                 new BigInteger[] { null, new BigInteger("1"), null, new BigInteger("2"), null },
                 Arrays.asList(new BigInteger[] { null, new BigInteger("1"), null, new BigInteger("2"), null }),
diff --git a/protostuff-runtime/src/test/java/io/protostuff/runtime/NullArrayElementTest.java b/protostuff-runtime/src/test/java/io/protostuff/runtime/NullArrayElementTest.java
index 7a946377..5c1343c8 100644
--- a/protostuff-runtime/src/test/java/io/protostuff/runtime/NullArrayElementTest.java
+++ b/protostuff-runtime/src/test/java/io/protostuff/runtime/NullArrayElementTest.java
@@ -516,7 +516,7 @@ public abstract class NullArrayElementTest extends AbstractTest
                 new String[] { null, "a", "b" },
                 new ByteString[] { null, ByteString.copyFromUtf8("a"), ByteString.copyFromUtf8("b") },
                 new byte[][] { null, new byte[] { 'a' }, new byte[] { 'b' } },
-                new BigDecimal[] { null, new BigDecimal(1.1d), new BigDecimal(2.2d) },
+                new BigDecimal[] { null, BigDecimal.valueOf(1.1), BigDecimal.valueOf(2.2) },
                 new BigInteger[] { null, new BigInteger("1"), new BigInteger("2") },
                 new Date[] { null, new Date(), new Date() },
                 new Size[] { null, Size.MEDIUM, Size.LARGE },
@@ -556,7 +556,7 @@ public abstract class NullArrayElementTest extends AbstractTest
                 new String[] { "a", "b", null },
                 new ByteString[] { ByteString.copyFromUtf8("a"), ByteString.copyFromUtf8("b"), null },
                 new byte[][] { new byte[] { 'a' }, new byte[] { 'b' }, null },
-                new BigDecimal[] { new BigDecimal(1.1d), new BigDecimal(2.2d), null },
+                new BigDecimal[] { BigDecimal.valueOf(1.1), BigDecimal.valueOf(2.2), null },
                 new BigInteger[] { new BigInteger("1"), new BigInteger("2"), null },
                 new Date[] { new Date(), new Date(), null },
                 new Size[] { Size.MEDIUM, Size.LARGE, null },
@@ -596,7 +596,7 @@ public abstract class NullArrayElementTest extends AbstractTest
                 new String[] { "a", null, "b" },
                 new ByteString[] { ByteString.copyFromUtf8("a"), null, ByteString.copyFromUtf8("b") },
                 new byte[][] { new byte[] { 'a' }, null, new byte[] { 'b' } },
-                new BigDecimal[] { new BigDecimal(1.1d), null, new BigDecimal(2.2d) },
+                new BigDecimal[] { BigDecimal.valueOf(1.1), null, BigDecimal.valueOf(2.2) },
                 new BigInteger[] { new BigInteger("1"), null, new BigInteger("2") },
                 new Date[] { new Date(), null, new Date() },
                 new Size[] { Size.MEDIUM, null, Size.LARGE },
@@ -636,7 +636,7 @@ public abstract class NullArrayElementTest extends AbstractTest
                 new String[] { null, "a", "b", null },
                 new ByteString[] { null, ByteString.copyFromUtf8("a"), ByteString.copyFromUtf8("b"), null },
                 new byte[][] { null, new byte[] { 'a' }, new byte[] { 'b' }, null },
-                new BigDecimal[] { null, new BigDecimal(1.1d), new BigDecimal(2.2d), null },
+                new BigDecimal[] { null, BigDecimal.valueOf(1.1), BigDecimal.valueOf(2.2), null },
                 new BigInteger[] { null, new BigInteger("1"), new BigInteger("2"), null },
                 new Date[] { null, new Date(), new Date(), null },
                 new Size[] { null, Size.MEDIUM, Size.LARGE, null },
@@ -676,7 +676,7 @@ public abstract class NullArrayElementTest extends AbstractTest
                 new String[] { null, "a", null, "b", null },
                 new ByteString[] { null, ByteString.copyFromUtf8("a"), null, ByteString.copyFromUtf8("b"), null },
                 new byte[][] { null, new byte[] { 'a' }, null, new byte[] { 'b' }, null },
-                new BigDecimal[] { null, new BigDecimal(1.1d), null, new BigDecimal(2.2d), null },
+                new BigDecimal[] { null, BigDecimal.valueOf(1.1), null, BigDecimal.valueOf(2.2), null },
                 new BigInteger[] { null, new BigInteger("1"), null, new BigInteger("2"), null },
                 new Date[] { null, new Date(), null, new Date(), null },
                 new Size[] { null, Size.MEDIUM, null, Size.LARGE, null },

@algomaster99
Copy link
Member

algomaster99 commented Sep 16, 2021

Yeah, I see the issue now. Seems really weird.

EDIT:

It is extremely weird because of the randomness of the diff generated. Sometimes there is + abstractstatic abstract class AbstractFoo^M and sometimes sniper printer doesn't even interfere with that type. Not sure how to go about this.

algomaster99 added a commit to algomaster99/spoon that referenced this issue Nov 30, 2021
algomaster99 added a commit to algomaster99/spoon that referenced this issue Nov 30, 2021
algomaster99 added a commit to algomaster99/spoon that referenced this issue Nov 30, 2021
@monperrus monperrus assigned monperrus and algomaster99 and unassigned monperrus Jan 14, 2022
@algomaster99 algomaster99 removed their assignment Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

3 participants