Skip to content

UseCollectionIsEmpty is not working as expected : changing the implementation logic #73

@subisueno

Description

@subisueno

Example below class -

`package sonar.autofix;

import java.util.List;

public class CollectionIsEmpty {

public void check(List<String> myList){
	if(myList.size() > 0){
		System.out.println("My List is not Empty.");
	}
	if(myList.size() <= 0){
		System.out.println("My List is Empty.");
	}
	if(myList.size() == 0){
		System.out.println("My List is Empty.");
	}
}

}
`

Run -

walkmod apply sonar:UseCollectionIsEmpty

After modification first "if-block" is expected to be changed to "!list.isEmpty()" (not operator is missing)

`package sonar.autofix;

import java.util.List;

public class CollectionIsEmpty {

public void check(List<String> myList){
	if(myList.isEmpty()){
		System.out.println("My List is not Empty.");
	}
	if(myList.size() <= 0){
		System.out.println("My List is Empty.");
	}
	if(myList.isEmpty()){
		System.out.println("My List is Empty.");
	}
}

}

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions