Remove this unused method parameter in Sonar - java

I got some trouble with a sonar issue:
Remove this unused method parameter "messageId".
well my method looks like:
private static Optional<Status> getStatus(Member member, String messageId) {
return Optional.ofNullable(member)
.map(Member::getTraffic)
.map(Traffic::getSymlinks)
.map(messages -> messages
.stream()
.filter(message -> message.getMessageId().equals(messageId))
.findFirst()).flatMap(message -> message.map(Message::getStatus));
}
the messageId is used inside the equals of the filter.
It is no field. It is the method parameter.
Is that a sonar bug or have I overlooked something?
We are using Sonar 5.6

Yeah, looks like a Bug . Seems this got recently addressed in SonarJava 5.0 (compatible with SonarQube 6.7+) which got released last December
https://jira.sonarsource.com/browse/SONARJAVA-2115

Related

SonarQube 8.1.0 is complaining about Call "Optional#isPresent()" before accessing the value

I get the error message: "Call "Optional#isPresent()" before accessing the value"
But as you can see in the image there is a isPresent() check right before that line.
Is this a bug of SonarQube?
-
ernest_k is right: (Thank you!)
Strictly speaking, when you call component.getId() for the second
time, you can't assume that it will give the same Optional instance
you called isPresent() on.
So I changed the code to:
Optional<String> optionalId = component.getId();
if (optionalId.isPresent()) {
String id = optionalId.get();
// ...
}

Kotlin Poet empty constructor generation - inheritance

I'm trying to print a call to superclass' constructor using KotlinPoet. My current (not compiling) output is:
open class NameOfASubclass : NameOfSuperclass {
}
In order to make my code compile I need to (somehow) either print
open class NameOfASubclass : NameOfSuperclass() {
}
or
open class NameOfASubclass : NameOfSuperclass {
constructor()
}
I cannot achieve it using KotlinPoet. Any ideas?
This is a bug. Here's the issue for it and here is the commit that fixes it.
There hasn't been a new release since this commit (16 of June), the last stable version is 0.3.0 (11th of June). Hopefully a new release is coming soon - there's been lots of work done since the previous one.
indeed in Kotlin Poet the problem is solved in v.0.4.0

avoid NullPointerException check

I am using SonarLint plugin (2.1.0) with Eclipse Mars (4.5.0) and I am getting : NullPointerException might be thrown as listToCheck is nullable here in this code:
if (checkListNotNull(listToCheck)) {
listToCheck.get(0); // I get here that warning
}
checkListNotNull is a method that returns true if the list that is passed is not null
Is possible to avoid this sonar warning?
Thanks
Just do that
if(listToCheck != null && !listToCheck.isEmpty()) {
listToCheck.get(0);
}
And I think the warning will disapear
(the use of another method seems to be useless in this case; the warning is just here because of Eclipse cannot understand what does your checkListNotNull do)

Sonar Java Web Client: Authors by line null

When running the following code on my Sonar, measure returns null. (Should return something on the lines of "1=author;2=author..."). However it works on nemo.sonarsource.org.
Other measures eg: violation work correctly on mine so this is probably not a question of faulty code. I suspect I need to configure Sonar somehow?
private final Sonar sonar;
public String getAuthors(String resourceKey){
return getMeasure(resourceKey, "authors_by_line").getData();
}
private Measure getMeasure(String resourceKey, String measureName){
Resource resource = sonar.find(ResourceQuery.createForMetrics(
resourceKey, measureName));
Measure measure = resource.getMeasure(measureName);
return measure;
}
You must have installed the SCM Activity plugin and enabled it (in Sonar settings, see the documentation on our Wiki) in order to be able to get this metric.
Then, once you have reanalysed your project, you'll get the expected behaviour.

JIRA - Jira post function -- How to update "fix version" field?

My scenario is: One step in my jira workflow should have the ability to unschedule a task i.e. set a Fix Version to "None".
I noticed that I was not able to update fix version in a workflow post function - I don't know exactly why, but anyway I did implement a jira plugin to help me solve my problem but I know I'm going against jira structure (even java good coding practices :)). I am not sure if my implementation can cause problems, but indeed it is working in my jira instance 4.1.x.
How I've implemented a plugin to update fix version in a post function, 2 very similar ways:
public class BrandsclubPostFunctionUnschedule extends AbstractJiraFunctionProvider {
// Here I create an empty Collection to be the new value of FixVersion (empty because I need no version in Fix Version)
public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
MutableIssue issue = this.getIssue(transientVars);
Collection<Version> newFixVersion = new ArrayList<Version>();
issue.setFixVersions(newFixVersion);
issue.store();
}
}
public class BrandsclubPostFunctionUnschedule extends AbstractJiraFunctionProvider {
// here I clear the Collection I got from "old" Fix Version and I have to set it again to make it work.
public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
MutableIssue issue = this.getIssue(transientVars);
Collection fixVersions = issue.getFixVersions();
fixVersions.clear();
issue.setFixVersions(fixVersions);
issue.store();
}
}
I presume that a real solution should use classes like: ChangeItemBean, ModifiedValue, IssueChangeHolder - taking as example the updateValue methods from CustomFieldImpl (from jira source code, project: jira, package: com.atlassian.jira.issue.fields).
My point of publishing this here is:
Does anyone know how to implement a jira plugin containing a post function to change Fix Version correctly?
If you want to do it properly take a look in the code for
./jira/src/java/com/atlassian/jira/workflow/function/issue/UpdateIssueFieldFunction.java processField()
Postfunctions that take input parameters are not documented yet it seems. Other places to go for code are other open source plugins.
Atlassian has a tutorial on doing just about exactly what you want to do, here:
I do it like in this snippet:
List<GenericValue> genericValueList = issueManager.getIssues(issues);
versionManager.moveIssuesToNewVersion(genericValueList, lastVersion, newVersion);

Categories