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

Wrong method history is retrieved #83

Open
agb94 opened this issue May 17, 2022 · 0 comments
Open

Wrong method history is retrieved #83

agb94 opened this issue May 17, 2022 · 0 comments

Comments

@agb94
Copy link

agb94 commented May 17, 2022

Hi,

I ran CodeShovel on Defects4J, and got some erroneous output.

Steps to reproduce

  1. Install defects4j

  2. Check out Lang-14b an reset to the actual buggy version c8afaa.

defects4j checkout -p Lang -v 14b -w /tmp/Lang-14b 
cd /tmp/Lang-14b
git reset --hard c8afaa
  1. Run CodeShovel for the methodequals (lines 781-783 in src/main/java/org/apache/commons/lang3/StringUtils.java)
java -Xmx2g -jar /root/workspace/tools/codeshovel-1.0.0-SNAPSHOT.jar -repopath /tmp/Lang-14b -filepath src/main/java/org/apache/commons/lang3/StringUtils.java -methodname equals -startline 781 -outfile output.json
  1. You may get the following output. fec5e4 is the only retrieved commit.
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
#########################################################################
STARTING ANALYSIS FOR FILE src/main/java/org/apache/commons/lang3/StringUtils.java
-------------------------------------------------------------------------
STARTING ANALYSIS FOR METHOD equals
====================================================
Running Analysis
Commit: HEAD
Method: equals
Lines: 781-783
====================================================

CodeShovel Change History: 
fec5e47638aeb2860a604daa0f424a91dbd9a166:Yintroduced(fec5e4:equals:752)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%% RESULT %%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
"fec5e47638aeb2860a604daa0f424a91dbd9a166": "Yintroduced",
FINISHED ANALYSIS FOR METHOD equals
RESULT FILE WRITTEN TO output.json
-------------------------------------------------------------------------
FINISHED ANALYSIS FOR FILE src/main/java/org/apache/commons/lang3/StringUtils.java
#########################################################################
Total duration: 11373

Issue

As you can see in the diff below, the retrieved commit fec5e4 has nothing to do with the target method 'equals'.

diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java
index 73aabe4..1ecf255 100644
--- a/src/main/java/org/apache/commons/lang3/StringUtils.java
+++ b/src/main/java/org/apache/commons/lang3/StringUtils.java
@@ -6491,14 +6491,4 @@ public class StringUtils {
         }
     }
 
-    static boolean regionMatchesSequence(CharSequence cs, boolean ignoreCase, int thisStart, 
-                                         CharSequence substring, int start, int length)
-    {
-        if (cs instanceof String) {
-            return ((String) cs).regionMatches(ignoreCase, thisStart, substring, start, length);
-        } else {
-            // TODO: Implement rather than convert to String
-            return cs.toString().regionMatches(ignoreCase, thisStart, substring, start, length);
-    }
-
 }

Git log output

git log -C -M -L 781,783:src/main/java/org/apache/commons/lang3/StringUtils.java

commit cf2e48a05c250feb636dd337dae1ffb7a1d9d411
Author: Gary D. Gregory <[email protected]>
Date:   Mon Mar 8 22:15:08 2010 +0000

    Change StringUtils arguments from String to CharSequence.
    
    Details: Working with (trunk) StringUtils (SU) I see the following emerge:
    
    - In SVN already and continuing: Change StringUtils arguments from String to CharSequence (CS).
    
    - This leads to replacing calls to String.substring(int[,int]) with calls to CharSequence.subSequence(int)
    
    - This leads to creating a CharSequenceUtils class (in SVN now, more on this new class below) and CharSequenceUtils.subSequence(CharSequence,int) to avoid changing "str.substring(start)" over and over to "str.subSequence(start, str.length())". For examples, see new versions of capitalize and uncapitalize.
    
    - We end up using a toString() on CharSequence to return a String from StringUtil when working with a CharSequence.
    
    So we have StringUtils using CharSequence inputs as much as possible instead of String, which is nice.
    
    The CharSequence method subSequence returns a CharSequence; though the Javadoc states "Returns a new CharSequence that is a subsequence of this sequence.", this does not guaranteed the return value to be the same kind of CharSequence as the receiver). Since we are after all in a class called StringUtil, calling toString() is a must.
    
    I propose that we create when possible the methods that are now StringUtils CharSequence methods into CharSequenceUtils and let StringUtil call CharSequenceUtils and then do its toString() and other String specific logic. Later we could have other CharSequence type of utils (for CharBuffer, StringBuiler, StringBuffer, etc) that use the 'primitives' from CharSequenceUtils.
    This means that for methods that are based solely on methods that are now in CharSequence, these can be moved to CharSequenceUtils without effort (all is* methods only call CharSequence#length() and charAt() for example and are now typed as CS, still in SU).
    
    We can leave @deprecateds method in SU as a nicety to avoid too much porting pain: First change the package to lang3 then you can 'optimize' by changing call sites from SU to CSU.
    
    As a start, I put in SVN a CharSequenceUtils (CSU) implementation for length() and subSequence().
    
    
    git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@920543 13f79535-47bb-0310-9956-ffa450edef68

diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java
--- a/src/main/java/org/apache/commons/lang3/StringUtils.java
+++ b/src/main/java/org/apache/commons/lang3/StringUtils.java
@@ -699,3 +699,3 @@
-    public static boolean equals(String str1, String str2) {
-        return str1 == null ? str2 == null : str1.equals(str2);
+    public static boolean equals(CharSequence cs1, CharSequence cs2) {
+        return cs1 == null ? cs2 == null : cs1.equals(cs2);
     }

commit f349629500ff5a85683dff0a807ff8e9b5b88809
Author: Gary D. Gregory <[email protected]>
Date:   Wed Apr 13 22:36:48 2005 +0000

    Removed extra C style parens in return statements (as discussed on commons-dev).
    
    git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@161229 13f79535-47bb-0310-9956-ffa450edef68

diff --git a/src/java/org/apache/commons/lang/StringUtils.java b/src/java/org/apache/commons/lang/StringUtils.java
--- a/src/java/org/apache/commons/lang/StringUtils.java
+++ b/src/java/org/apache/commons/lang/StringUtils.java
@@ -668,3 +668,3 @@
     public static boolean equals(String str1, String str2) {
-        return (str1 == null ? str2 == null : str1.equals(str2));
+        return str1 == null ? str2 == null : str1.equals(str2);
     }

commit d23b22c78078ee7468e797e80188ae9508c0eee0
Author: Henri Yandell <[email protected]>
Date:   Fri Jul 19 03:35:56 2002 +0000

    Initial copy from jakarta-commons-sandbox
    
    
    git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@136932 13f79535-47bb-0310-9956-ffa450edef68

diff --git a/src/java/org/apache/commons/lang/StringUtils.java b/src/java/org/apache/commons/lang/StringUtils.java
--- /dev/null
+++ b/src/java/org/apache/commons/lang/StringUtils.java
@@ -0,0 +157,3 @@
+    public static boolean equals(String str1, String str2) {
+        return (str1 == null ? str2 == null : str1.equals(str2));
+    }

Can you please look into this issue? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant