0

I have a class MyClass that has a method getId() with return type Long. I am using it with optaplanner. I create a solver factory from a resource file and build a solver.

SolverFactory solverFactory = SolverFactory.createFromXmlResource("/path/to/config");
Solver solve = solverFactory.buildSolver();

When buildSolver() is executed, I see the warning

Getter overloading detected in class mypackage.MyClass : getId (class java.lang.Object) vs getId (class java.lang.Long) 

I am wondering where optaplanner finds the method getId() with return type Object. It is nowhere in the source code!

EDIT

As pointed out in the comments, the warning could also mean, that drools has found two methods: getId(Object) and getId(Long). This is even more suspicious, since I did not define a getId method that takes any parameters.

UPDATE

I have investigated the class https://github.com/kiegroup/drools/blob/master/drools-core/src/main/java/org/drools/core/util/asm/ClassFieldInspector.java in the version that I have on my machine using the maven dependency

<dependency>
  <groupId>org.optaplanner</groupId>
  <artifactId>optaplanner-benchmark</artifactId>
  <version>6.4.0.Final</version>
</dependency>

When the ClassFieldInspector is instanciated with classUnderInspection equals "mypackage.MyClass", then the list of methods

final List<Method> methods = Arrays.asList( clazz.getMethods() );

does indeed contain two methods called getId():

  1. "public java.lang.Long mypackage.myClass.getId()"
  2. "public java.lang.Object mypackage.myClass.getId()"
JCvanDamme
  • 621
  • 5
  • 20
  • 1
    I doubt anyone will be able to help without a [mcve]. – T.J. Crowder Jun 23 '17 at 14:31
  • It is just a check which is done by Drools/Optaplanner, but it depends on your application if it may result in a problem. Warning is generated by this class: https://github.com/kiegroup/drools/blob/master/drools-core/src/main/java/org/drools/core/util/asm/ClassFieldInspector.java – Dominik Sandjaja Jun 23 '17 at 14:32
  • 1
    @Geoffrey De Smet If the warning does mean that there might be two getId methods with different return types it is absolutely suspicious since there is no overloading for various return types. – laune Jun 23 '17 at 14:54
  • The message you cited doesn't say anything about return types. Where did return types enter into your analysis? – Lew Bloch Jun 23 '17 at 15:36
  • @LewBloch, I do have a getIt() method with return type Long and without any parameters. So I thought the engine has detected the same method, but with Object instead of Long – JCvanDamme Jun 23 '17 at 15:46
  • Right, but the error message didn't say anything about return types. It talked about overloads and argument types. If a doctor examined your legs simply because you have them instead of addressing your headache, would that help? The error message steers you in a direction. Going in an entirely different direction is unlikely to help anything. – Lew Bloch Jun 23 '17 at 15:49
  • How did you manage to compile myClass? The Java Language Specification doesn't allow to have 2 methods with the same name (getId) and same arguments (none) in the same class that have a different return type (Long and Object). What is possible is that `public Long myClass.getId()` overwrites `public Object myParent.getId()`. Is that the case? Please copy the relevant class and superclasses code here (even if it's another JVM lang). – Geoffrey De Smet Jun 25 '17 at 05:22
  • The Drools warning message could be better, so [I created a jira](https://issues.jboss.org/browse/DROOLS-1632). We'll need those relevant class and superclasses source code here to reproduce and fix it. – Geoffrey De Smet Jun 25 '17 at 05:35

1 Answers1

0

The problem was caused by the fact that MyClass implements a generic interface that declares the method getId. I have posted this as a separate question

Implementing generic java interface adds additional method

because of its general nature not related to optaplanner.

JCvanDamme
  • 621
  • 5
  • 20