6

When running "gradle build" I got the following error with one of our projects, couple of the classes get the following compile error:

cannot be applied to given types;
                this._logFilter.setFirstResult(firstResult);
                               ^
  required: int
  found: long
  reason: actual argument long cannot be converted to int by method invocation conversion

Even though, the method setFirstResult takes a long as parameter. Here is the code:

public void setFirstResult(long firstResult) {
    this._firstResult = firstResult;
}

I have tried --refresh-dependencies and cleared out cache etc. None of those worked for me. In addition, this project was a maven project, I converted it over to use gradle instead.

Edit:

I'm adding additional context here per the request from the comments:

Here is the source code for the this._logFilter

public class GlobalMessageLogFilter {
    private long _firstResult = 0L;

    private long _maxResults = 100L;

    private Application _application;

    private SeverityLevelEnum _severityLevel;

    private EnvironmentEnum _environment;

    private String _userName;

    private Category _category;

    public EnvironmentEnum getEnvironment() {
        return this._environment;
    }

    public void setEnvironment(EnvironmentEnum environment) {
        this._environment = environment;
    }

    public long getFirstResult() {
        return this._firstResult;
    }

    public void setFirstResult(long firstResult) {
        this._firstResult = firstResult;
    }

    public long getMaxResults() {
        return this._maxResults;
    }

    public void setMaxResults(long maxResults) {
        this._maxResults = maxResults;
    }

    public Application getApplication() {
        return this._application;
    }

    public void setApplication(Application application) {
        this._application = application;
    }

    public SeverityLevelEnum getSeverityLevel() {
        return this._severityLevel;
    }

    public void setSeverityLevel(SeverityLevelEnum severityLevel) {
        this._severityLevel = severityLevel;
    }

    public String getUserName() {
        return this._userName;
    }

    public void setUserName(String userName) {
        this._userName = userName;
    }

    public Category getCategory() {
        return this._category;
    }

    public void setCategory(Category category) {
        this._category = category;
    }
}

Here is the full stack-trace

λ gradle build
:compileJava
C:\Java Source\wicket\administration\GlobalMessageLogProvider.java:36: error: method setFirstResult in class GlobalMessageLogFilter cannot be applied to given types;
                this._logFilter.setFirstResult(firstResult);
                               ^
  required: int
  found: long
  reason: actual argument long cannot be converted to int by method invocation conversion
C:\Java Source\wicket\administration\GlobalMessageLogProvider.java:37: error: method setMaxResults in class GlobalMessageLogFilter cannot be applied to given types;
                this._logFilter.setMaxResults(maxResults);
                               ^
  required: int
  found: long
  reason: actual argument long cannot be converted to int by method invocation conversion
C:\Java Source\wicket\administration\users\UserSecurityProvider.java:35: error: method setFirst in class UserSearchFilter cannot be applied to given types;
                this._filter.setFirst(first);
                            ^
  required: int
  found: long
  reason: actual argument long cannot be converted to int by method invocation conversion
C:\Java Source\wicket\administration\users\UserSecurityProvider.java:36: error: method setCount in class UserSearchFilter cannot be applied to given types;
                this._filter.setCount(count);
                            ^
  required: int
  found: long
  reason: actual argument long cannot be converted to int by method invocation conversion

Edit: added the source code of GlobalMessageLogProvider

public class GlobalMessageLogProvider extends SortableDataProvider<GlobalMessageLog, String>
{
    @SpringBean
    private GlobalMessageLogRepository _globalMessageLogRepository;
    private GlobalMessageLogFilter _logFilter;
    private boolean _searchAllowed = false;


    public GlobalMessageLogProvider(GlobalMessageLogFilter globalMessageLogFilter)
    {
        Injector.get().inject(this);
        this._logFilter = globalMessageLogFilter;
    }


    @Override
    public Iterator<? extends GlobalMessageLog> iterator(long firstResult, long maxResults)
    {
        this._logFilter.setFirstResult(firstResult);
        this._logFilter.setMaxResults(maxResults);
        Iterator<GlobalMessageLog> results = Arrays.<GlobalMessageLog> asList().iterator();

        if (this._searchAllowed)
        {
            if (super.getSort() == null)
            {
                results = this._globalMessageLogRepository.search(this._logFilter, "id", false).iterator();
            } else
            {
                results =
                        this._globalMessageLogRepository.search(this._logFilter,
                                super.getSort().getProperty(),
                                super.getSort().isAscending()).iterator();
            }
        }
        return results;
    }
}
CharlesC
  • 1,310
  • 14
  • 26
  • Maybe `this._firstResult` is an `int`? – Joop Eggen Jul 17 '15 at 14:54
  • @JoopEggen Pretty sure is a `long` .... `private long _firstResult = 0L;` – CharlesC Jul 17 '15 at 15:28
  • Could you provide a simplified example that reproduces the problem? – Opal Jul 17 '15 at 16:03
  • 1
    The error message says, the `int` is required, so could it be the case that Gradle uses another .setFirstResult method declaration (built-in one?), but you provide a `long`, so here a type mismatch. – Aliaksandr Kazlou Jul 17 '15 at 16:43
  • @zshamrock Nope, unfortunately that is not the case here. As if it is, i would expect Eclipse catch that as well. – CharlesC Jul 17 '15 at 17:02
  • A stacktrace + the source code for the `_logFilter` type might help. There's not enough context in the question to diagnose the error. The workaround is to cast the argument: `setFirstResult((int) firstResult)`. – Peter Ledbrook Jul 19 '15 at 08:04
  • Thank you for checkout out my question, @PeterLedbrook i added more context as you requested. – CharlesC Jul 20 '15 at 14:30
  • 1
    Could you show some code about `GlobalMessageLogProvider.java:36`? Where's `this._logFilter` set? – stef77 Jul 20 '15 at 14:37
  • @stef77 source code have been attached. Thank you. – CharlesC Jul 20 '15 at 19:32
  • Hmmmm... Any chance you've got a class which defines `setFirstResult(int firstResult)`? Perhaps a subclass of `GlobalMessageLogFilter`? Such that Gradle perhaps doesn't know which class to use? Where's the parameter `globalMessageLogFilter` of the constructor coming from, is this obtained via injection (sorry, I'm not familiar with Spring)? Or do you instantiate this object somewhere? – stef77 Jul 20 '15 at 22:03
  • Can you somehow verify that gradle uses the correct dependencies with the correct version...? https://discuss.gradle.org/t/gradle-plugin-build-pulls-in-wrong-version-of-commons-io/1788/4 – stef77 Jul 20 '15 at 22:10
  • You appear to have a very unconventional directory structure. Which is the build directory? Which is the source directory? Are any classes in packages? My best guess is that the Java compiler is picking up an old version of `GlobalMessageLogFilter` that used `int` rather than `long`. – Peter Ledbrook Jul 21 '15 at 07:46

1 Answers1

0

I found out the issue and I was able to get it resolved. Majority comment pointed out the setFirstResult(int firstResult) is the wrong version of class it been using. they are correct.

Bascially, the GlobalMessageLogProvider was been changed, but the latest verison of jar has never been pushed to the Nexus sever(our own private third party dependency server). so, whenever I pull the jar down, it always reference the old one.

After manually push the latest jar to the Nexus server and i was able to successfully build the project with gradle without error.

So Take-away from this question: We need create a build process that will automatically build/push latest version of jar to the Nexus server. I'm thinking about create the build/push process through our TeamCity build server with some customized command/script. (Please feel free to provide any better suggestion/practice tips if there are).

Thank you everyone for the kindness help, I sincerely appreciated.

CharlesC
  • 1,310
  • 14
  • 26
  • I think you should look into configuration management, which can assure you that only versions known to work together are used. There seems to be some weirdness in your component development, too - how can it be that you seem to have the "long" version of a jar locally (so your IDE doesn't complain about the wrong parameter), but Gradle pulls the jar from the Nexus? Have you changed the source locally and not committed? In that case, you probably shouldn't reference the source in your project, but only the library, the jar, containing the method. This way, your IDE would have warned you. – stef77 Jul 21 '15 at 19:44
  • @stef77 Yea, actually that is one of the thing I don't quite get. It seems like the Gradle is behavior strangely. Basically, i have noticed, the gradle will always use the jar out of the ".m2" folder. If the jar does not exists, then it will grab it from Nexus. I suspect the reason is because not all projects has been converted to gradle. (some of the old project still using maven). so gradle have no idea what to do in that case. Even the type change have happened locally, the IDE(Eclipse) didn't complain for any type error. – CharlesC Jul 22 '15 at 20:36