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

Existing Sorald code is not generating remediated code #589

Closed
PrakashNayak opened this issue Aug 12, 2021 · 8 comments · Fixed by #591
Closed

Existing Sorald code is not generating remediated code #589

PrakashNayak opened this issue Aug 12, 2021 · 8 comments · Fixed by #591
Labels
bug Something isn't working

Comments

@PrakashNayak
Copy link

Steps I followed


  1. git clone https://github.com/SpoonLabs/sorald.git

  2. cd sorald

  3. mvn package -DskipTests
    4 cp target/sorald-*-jar-with-dependencies.jar sorald.jar

  4. Opend the command prompt
    Ran below command
    repair --source C:/test/solard_code/sonarqube-repair/source/act/UnusedPrivateField .java --rule-key 1068

  5. This is Original file
    public class UnusedPrivateField {
    private String a = "Hello world!";

    public int compute(int number) {
    return number * 42;
    }
    }

Output in console


INFO JavaClasspath initialization
INFO JavaClasspath initialization (done) | time=81ms
INFO JavaTestClasspath initialization
INFO JavaTestClasspath initialization (done) | time=0ms
INFO Java Main Files AST scan
INFO 1 source files to be analyzed
INFO 1/1 source files have been analyzed
INFO Java Main Files AST scan (done) | time=1273ms
INFO Java Test Files AST scan
INFO 0 source files to be analyzed
INFO Java Test Files AST scan (done) | time=1ms
INFO 0/0 source files have been analyzed
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
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------
UnusedPrivateFieldProcessor: 0
-----End of report------

I want answer of below questions


1 . Why its not removing the unused private variable?
2. Where file will get generated ?
3. Am I doing any mistake in running the command
Testing.zip

I want to two things here first it should remove the unused variable and remove the unusedprivate fields.

Please help me and let me know @prakash.bit.nayak@gmail.com

@PrakashNayak PrakashNayak changed the title Existing Sorald code is not genearting remeded code Existing Sorald code is not genearting remediated code Aug 12, 2021
@PrakashNayak PrakashNayak changed the title Existing Sorald code is not genearting remediated code Existing Sorald code is not generating remediated code Aug 12, 2021
@algomaster99
Copy link
Member

Hello, I will try to answer your questions.

1 . Why its not removing the unused private variable?

I am trying on Linux and it works for me. I ran the command below.

java -jar target/sorald-0.3.1-SNAPSHOT-jar-with-dependencies.jar repair --source UnusedPrivateField.java --rule-key 1068
  1. Where file will get generated ?

The source file you pass using --source flag gets modified.

  1. Am I doing any mistake in running the command

On the first try, your soruce file would have been repaired and now there are no violations so sorald does nothing like your console says. Verify your Testing.java and UnusedPrivateField.java to see if they actually have violations now. If not, introduce some, and run the above command.

@slarse
Copy link
Collaborator

slarse commented Aug 12, 2021

Hi @PrakashNayak,

1 . Why its not removing the unused private variable?

That repair works fine on my end, so likely there is something ##with your environment that is causing Sorald to not do its job. Based on the file path, it looks like you are running Windows? Sorald currently isn't tested on Windows (see #273), and so there may be some Windows-specific problem. I don't have a Windows machine at hand right now, but I can try running this on Windows tonight after work hours to see if that's where the problem stems from.

  1. Where file will get generated ?

By default, the repair is enacted in-place. That is to say, the input file is overwritten.

  1. Am I doing any mistake in running the command

The one thing that strikes me as a little bit odd is that the filepath starts with C:, indicating Windows, but it's /-separated as opposed to \-separated, the latter being the default on Windows.

Could you provide the output of mvn --version?

@slarse
Copy link
Collaborator

slarse commented Aug 12, 2021

Also what @algomaster99 said about the in-place repair: you might already have repaired the violation.

@algomaster99
Copy link
Member

algomaster99 commented Aug 12, 2021

@slarse I just tried on Windows and it doesn't work. I get the same output as @PrakashNayak

...
-----Number of fixes------
UnusedPrivateFieldProcessor: 0
-----End of report------

I tried debugging it and found out that it is able to detect the position of violation but sorald is not able to repair it. The BestFitScanner is not able to compute best fit for the violation on Windows, I think. We can open an issue for this. It seems like a platform dependent bug.

@slarse
Copy link
Collaborator

slarse commented Aug 12, 2021

Good, then we know it's a Windows thing.

The BestFitScanner is not able to compute best fit for the violation on Windows,

On a limb, that's likely something with an assumption of how filepaths work that doesn't hold on Windows. This kind of falls into #273 though, we just need to officially add support for Windows.

@slarse slarse added the bug Something isn't working label Aug 12, 2021
@PrakashNayak
Copy link
Author

My Maven Version is --> Apache Maven 3.6.3

@slarse
Copy link
Collaborator

slarse commented Aug 12, 2021

Hi @PrakashNayak ,

Could you give the full output of mvn --version? It includes a lot more than just the version of Maven itself (including OS, JDK version, character encodings etc).

In any case, we've narrowed this down to a bug in using Sorald with Windows. Unfortunately, we do not currently support Windows, but it is in the pipeline (see #273).

@slarse
Copy link
Collaborator

slarse commented Aug 13, 2021

@PrakashNayak If you're in a hurry you can try the version on the branch in #591, it should work for you. We'll have it merged into master sometime next week.

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

Successfully merging a pull request may close this issue.

3 participants