JQL Function: actual and formal argument lists differ in length

Hi,

I’m working on a JQL function that is supposed to filter issues based on the value in a specified custom field. However, I’m running into a problem in getting components. I need access to JqlQueryBuilder and SearchService in order to return a list of issues to filter but I’m currently running into a strange problem when trying to grab these components via my class’s constructor.

I’ve worked on a JQL function before and managed to complete it using the exact method I’ve outlined here but for some reason when it worked then, it doesn’t work now. I’ve also worked on a Project Tab Panel in which I used ComponentAccessor to get the component objects but it doesn’t seem this method works with JQL functions.

Anyway, the problem I’m having is that the test classes created by the Atlassian SDK when I create my plugin module use a default constructor of my class instead of injecting in the components that are used as parameters to my constructor resulting in the compilation error: “actual and formal argument lists differ in length”.

I’ve tried to delete the test classes or remove it from the project so it doesn’t run tests but then I end up unable to create projects due to an unknown error in my local dev instance. Does anyone have any idea why this could be happening

Here is the output from atlas-run

C:\projects\JIRA-plugins-old\issue-risk\issue-risk-levels>atlas-run
Executing: "C:\Applications\Atlassian\atlassian-plugin-sdk-6.2.14\apache-maven-3.2.1\bin\mvn.bat" com.atlassian.maven.plugins:maven-amps-dispatcher-plugin:"6.2.11":run -gs C:\Applications\Atlassian\atlassian-plugin-sdk-6.2.14\apache-maven-3.2.1/conf/settings.xml
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256M; support was removed in 8.0
[INFO] Scanning for projects...
Downloading: file://C:\Applications\Atlassian\atlassian-plugin-sdk-6.2.14/repository/org/apache/maven/plugins/maven-resources-plugin/maven-metadata.xml
Downloading: https://maven.atlassian.com/repository/public/org/apache/maven/plugins/maven-resources-plugin/maven-metadata.xml
Downloaded: https://maven.atlassian.com/repository/public/org/apache/maven/plugins/maven-resources-plugin/maven-metadata.xml (812 B at 0.7 KB/sec)
Downloading: file://C:\Applications\Atlassian\atlassian-plugin-sdk-6.2.14/repository/org/apache/maven/plugins/maven-compiler-plugin/maven-metadata.xml
Downloading: https://maven.atlassian.com/repository/public/org/apache/maven/plugins/maven-compiler-plugin/maven-metadata.xml
Downloaded: https://maven.atlassian.com/repository/public/org/apache/maven/plugins/maven-compiler-plugin/maven-metadata.xml (994 B at 3.2 KB/sec)
Downloading: https://maven.atlassian.com/repository/public/org/apache/maven/plugins/maven-install-plugin/maven-metadata.xml
Downloading: file://C:\Applications\Atlassian\atlassian-plugin-sdk-6.2.14/repository/org/apache/maven/plugins/maven-install-plugin/maven-metadata.xml
Downloaded: https://maven.atlassian.com/repository/public/org/apache/maven/plugins/maven-install-plugin/maven-metadata.xml (623 B at 1.4 KB/sec)
Downloading: file://C:\Applications\Atlassian\atlassian-plugin-sdk-6.2.14/repository/org/apache/maven/plugins/maven-deploy-plugin/maven-metadata.xml
Downloading: https://maven.atlassian.com/repository/public/org/apache/maven/plugins/maven-deploy-plugin/maven-metadata.xml
Downloaded: https://maven.atlassian.com/repository/public/org/apache/maven/plugins/maven-deploy-plugin/maven-metadata.xml (709 B at 1.8 KB/sec)
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building issue-risk-levels 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-amps-dispatcher-plugin:6.2.11:run (default-cli) @ issue-risk-levels >>>
Downloading: file://C:\Applications\Atlassian\atlassian-plugin-sdk-6.2.14/repository/org/apache/velocity/velocity/maven-metadata.xml
Downloading: http://repo.maven.apache.org/maven2/org/apache/velocity/velocity/maven-metadata.xml
Downloading: https://maven.atlassian.com/repository/public/org/apache/velocity/velocity/maven-metadata.xml
Downloaded: http://repo.maven.apache.org/maven2/org/apache/velocity/velocity/maven-metadata.xml (636 B at 3.5 KB/sec)
Downloaded: https://maven.atlassian.com/repository/public/org/apache/velocity/velocity/maven-metadata.xml (2 KB at 3.5 KB/sec)
[INFO]
[INFO] --- maven-jira-plugin:6.2.11:compress-resources (default-compress-resources) @ issue-risk-levels ---
[WARNING] File encoding has not been set, using platform encoding windows-1252, i.e. build is platform dependent!
[INFO] Compiling javascript using YUI
[INFO] 0 Javascript file(s) were minified into target directory C:\projects\JIRA-plugins-old\issue-risk\issue-risk-levels\target\classes
[INFO] 0 CSS file(s) were minified into target directory C:\projects\JIRA-plugins-old\issue-risk\issue-risk-levels\target\classes
[INFO] Compressing XML files
[INFO] 0 XML file(s) were minified into target directory C:\projects\JIRA-plugins-old\issue-risk\issue-risk-levels\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ issue-risk-levels ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 8 resources
[INFO]
[INFO] --- maven-jira-plugin:6.2.11:filter-plugin-descriptor (default-filter-plugin-descriptor) @ issue-risk-levels ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.6.2:compile (default-compile) @ issue-risk-levels ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-jira-plugin:6.2.11:generate-rest-docs (default-generate-rest-docs) @ issue-risk-levels ---
[INFO]
[INFO] --- atlassian-spring-scanner-maven-plugin:1.2.13:atlassian-spring-scanner (default) @ issue-risk-levels ---
[INFO] Starting Atlassian Spring Byte Code Scanner...
[INFO]
[INFO]
[INFO]  Analysis ran in 209 ms.
[INFO]  Encountered 4 total classes
[INFO]  Processed 3 annotated classes
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) @ issue-risk-levels ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-jira-plugin:6.2.11:filter-test-plugin-descriptor (default-filter-test-plugin-descriptor) @ issue-risk-levels ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.6.2:testCompile (default-testCompile) @ issue-risk-levels ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 4 source files to C:\projects\JIRA-plugins-old\issue-risk\issue-risk-levels\target\test-classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/projects/JIRA-plugins-old/issue-risk/issue-risk-levels/src/test/java/ut/com/teledyne/jira/plugins/jql/IssueWithCustomFieldValueTest.java:[39,20] constructor IssueWithCustomFieldValue in class com.teledyne.jira.plugins.jql.IssueWithCustomFieldValue cannot be applied to given types;
  required: com.atlassian.jira.jql.parser.JqlQueryParser
  found: no arguments
  reason: actual and formal argument lists differ in length
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.343 s
[INFO] Finished at: 2017-08-22T08:28:03-08:00
[INFO] Final Memory: 56M/289M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.2:testCompile (default-testCompile) on project issue-risk-levels: Compilation failure
[ERROR] /C:/projects/JIRA-plugins-old/issue-risk/issue-risk-levels/src/test/java/ut/com/teledyne/jira/plugins/jql/IssueWithCustomFieldValueTest.java:[39,20] constructor IssueWithCustomFieldValue in class com.teledyne.jira.plugins.jql.IssueWithCustomFieldValue cannot be applied to given types;
[ERROR] required: com.atlassian.jira.jql.parser.JqlQueryParser
[ERROR] found: no arguments
[ERROR] reason: actual and formal argument lists differ in length
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

And here is my java class

package com.teledyne.jira.plugins.jql;

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.jql.parser.JqlQueryParser;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.plugin.spring.scanner.annotation.component.Scanned;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.atlassian.jira.JiraDataType;
import com.atlassian.jira.JiraDataTypes;
import com.atlassian.jira.jql.operand.QueryLiteral;
import com.atlassian.jira.jql.query.QueryCreationContext;
import com.atlassian.jira.plugin.jql.function.AbstractJqlFunction;
import com.atlassian.jira.util.MessageSet;
import com.atlassian.jira.util.NotNull;
import com.atlassian.query.clause.TerminalClause;
import com.atlassian.query.operand.FunctionOperand;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;


@Scanned
public class IssueWithCustomFieldValue extends AbstractJqlFunction
{
    private static final Logger log = LoggerFactory.getLogger(IssueWithCustomFieldValue.class);

    @ComponentImport
    private final JqlQueryParser jqlQueryParser;

    public IssueWithCustomFieldValue(JqlQueryParser jqlQueryParser)
    {
        this.jqlQueryParser = jqlQueryParser;
    }

    public MessageSet validate(ApplicationUser searcher, FunctionOperand operand, TerminalClause terminalClause)
    {
        return validateNumberOfArgs(operand, 1);
    }

    public List<QueryLiteral> getValues(QueryCreationContext queryCreationContext, FunctionOperand operand, TerminalClause terminalClause)
    {
        final List<QueryLiteral> literals = new LinkedList<QueryLiteral>();
        return literals;
    }

    public int getMinimumNumberOfExpectedArguments()
    {
        return 1;
    }

    public JiraDataType getDataType()
    {
        return JiraDataTypes.TEXT;
    }
}

Hi @neil.sonnenberg,

Can you please share your logs and Atlassian SDK version?

Thanks!

Cheers,
Anne Calantog

Thank you so much for responding to my question.

I’ve added the output from when I try to run ‘atlas-run’ which is where it produces the compilation error. I’m using the Atlassian SDK 6.2.14 which I believe is the newest one. I will also add the java class I created for the JQL function in case that would be useful.

Thank you,
Neil

Hi @neil.sonnenberg,

Thanks for sharing you class. Can you please try to put @Inject annotation in your constructor and finalize the dependency in the argument?

Thanks!

Cheers,
Anne Calantog

Sorry, I’m pretty new to plugin development. What do you mean by finalizing the dependency in the argument?

Thank you,
Neil

Hi @neil.sonnenberg,

My bad. Just put “final” before the dependency.

Thanks!

Cheers,
Anne Calantog

I’ve tried adding both and I got the same error. Any other ideas?

Thanks,
Neil

Hi @neil.sonnenberg,

I created a fresh Jira Plugin via atlas-create-jira-plugin command, added your class (with the updated @Inject and final keyword), and run atlas-run. And was able to run and access it. Any additional info?

Cheers,
Anne Calantog

Alright I tried creating a fresh Jira Plugin the same way. I used atlas-create-jira-plugin-module to create a JQL function class then pasted my code with the @Inject and final keyword and I still got the same issue. Is there a problem with atlas-create-jira-plugin-module? Or should I reinstall my SDK?

Like I said in my original post the weird part is that when I did my first JQL function using the same methods 2 or 3 weeks ago it worked flawlessly. I have no idea why it won’t work now.

Hi @neil.sonnenberg,

You still get the:

[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/projects/JIRA-plugins-old/issue-risk/issue-risk-levels/src/test/java/ut/com/teledyne/jira/plugins/jql/IssueWithCustomFieldValueTest.java:[39,20] constructor IssueWithCustomFieldValue in class com.teledyne.jira.plugins.jql.IssueWithCustomFieldValue cannot be applied to given types;
  required: com.atlassian.jira.jql.parser.JqlQueryParser
  found: no arguments
  reason: actual and formal argument lists differ in length

I don’t have that Test class in my plugin. Can you share it for reference? Also, have you tried running “atlas-clean” or “atlas-mvn clean”

Thanks!

Cheers,
Anne Calantog

Sorry for the really late response. I sort of forgot about this thread once I figured out the issue. It’s not exactly a solution but my workaround was to just delete the test classes. The problem lied in the arguments differing between the pre-created test cases which were sort of pointless anyway so deleting them doesn’t cause any issue.

Thank you for your help,
Neil