This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 268507 - Sintax error: CriteriaBuilder, no suitable method found
Summary: Sintax error: CriteriaBuilder, no suitable method found
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Compiler (show other bugs)
Version: 8.2
Hardware: PC Windows 10 x64
: P3 normal with 4 votes (vote)
Assignee: Dusan Balek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-10-13 13:57 UTC by FiruzzZ
Modified: 2017-10-31 14:17 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
IDE log (106.93 KB, text/plain)
2016-10-13 13:57 UTC, FiruzzZ
Details

Note You need to log in before you can comment on or make changes to this bug.
Description FiruzzZ 2016-10-13 13:57:00 UTC
Netbeans 8.2 throws sintax error on: 
    cb.lessThanOrEqualTo(root.get(PresupuestoDiscapacidad_.periodoDesde), desde) 
and  cb.greaterThanOrEqualTo(root.get(PresupuestoDiscapacidad_.periodoHasta), hasta)

//CODE
CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
        CriteriaQuery<PresupuestoDiscapacidad> cq = cb.createQuery(getEntityClass());
        Root<PresupuestoDiscapacidad> root = cq.from(getEntityClass());
        cq.where(
                cb.and(
                        cb.equal(root.get(PresupuestoDiscapacidad_.cliente), cliente),
                        cb.equal(root.get(PresupuestoDiscapacidad_.paciente), paciente),
                        cb.lessThanOrEqualTo(root.get(PresupuestoDiscapacidad_.periodoDesde), desde),
                        cb.greaterThanOrEqualTo(root.get(PresupuestoDiscapacidad_.periodoHasta), hasta)
                )
        );

Creating local variables solves the problem:

Path<Date> desdePath = root.get(PresupuestoDiscapacidad_.periodoDesde);
Path<Date> hastaPath = root.get(PresupuestoDiscapacidad_.periodoHasta);
        cq.where(cb.and(cb.equal(root.get(PresupuestoDiscapacidad_.cliente), cliente),
                        cb.equal(root.get(PresupuestoDiscapacidad_.paciente), paciente),
                        cb.lessThanOrEqualTo(desdePath, desde),
                        cb.greaterThanOrEqualTo(hastaPath, hasta)
                )
        );

This is already reported in some comments like:
http://stackoverflow.com/questions/9449003/compare-date-entities-in-jpa-criteria-api

This is the message from the IDE: 
no suitable method found for greaterThanOrEqualTo(Path<Date>,Date)
    method CriteriaBuilder.<Y#1>greaterThanOrEqualTo(Expression<? extends Y#1>,Expression<? extends Y#1>) is not applicable
      (cannot infer type-variable(s) Y#1,Y#2
        (argument mismatch; Date cannot be converted to Expression<? extends Y#1>))
    method CriteriaBuilder.<Y#3>greaterThanOrEqualTo(Expression<? extends Y#3>,Y#3) is not applicable
      (inference variable Y#2 has incompatible bounds
        equality constraints: Date
        upper bounds: Comparable<? super Y#3>,Date,Object)
  where Y#1,Y#2,X,Y#3 are type-variables:
    Y#1 extends Comparable<? super Y#1> declared in method <Y#1>greaterThanOrEqualTo(Expression<? extends Y#1>,Expression<? extends Y#1>)
    Y#2 extends Object declared in method <Y#2>get(SingularAttribute<? super X,Y#2>)
    X extends Object declared in interface Path
    Y#3 extends Comparable<? super Y#3> declared in method <Y#3>greaterThanOrEqualTo(Expression<? extends Y#3>,Y#3)


Product Version = NetBeans IDE 8.2 (Build 201609300101)
Operating System = Windows 10 version 10.0 running on amd64
Java; VM; Vendor = 1.8.0_102
Runtime = Java HotSpot(TM) 64-Bit Server VM 25.102-b14

Reproducibility: Happens every time
Comment 1 FiruzzZ 2016-10-13 13:57:06 UTC
Created attachment 162493 [details]
IDE log
Comment 2 ender01 2016-11-01 12:42:28 UTC
Experienced the same issue with following:

Product Version: NetBeans IDE 8.2 (Build 201609300101)
Java: 1.8.0_91; Java HotSpot(TM) 64-Bit Server VM 25.91-b14
Runtime: Java(TM) SE Runtime Environment 1.8.0_91-b14
System: Mac OS X version 10.11.6 running on x86_64; UTF-8; en_US (nb)

Projects are all Maven based, with spring-boot/hibernate defaults. This is also a fresh install (as of 11-1-2016).
Comment 3 asafbennatan 2016-12-27 19:12:10 UTC
same issue for me as well,
the error mark dissapapers if i seperate the expression like :


Predicate p1=cb.equal(root.get(PresupuestoDiscapacidad_.cliente), cliente);
Predicate p2=cb.equal...
Predicate p3=cb.equal...
Predicate p4=cb.equal...
cq.where(cb.and(p1,p2,p3,p4))
Comment 4 FCR 2017-03-16 10:18:27 UTC
Another way to reproduce: 

import java.util.Collections;
import com.google.common.collect.ImmutableList;

private class A{
	public void setMinVal(int val1, int val2){
		setVal(Collections.min(ImmutableList.of(val1, val2))); // error
		setVal(Collections.<Integer>min(ImmutableList.of(val1, val2)));
	}
	
	private void setVal(int i){}
}

Error:
no suitable method found for min(ImmutableList<Integer>)
    method Collections.<T#1>min(Collection<? extends T#1>) is not applicable
      (inference variable E has incompatible bounds
        upper bounds: Comparable<? super T#1>,Object
        lower bounds: Integer)
    method Collections.<T#2>min(Collection<? extends T#2>,Comparator<? super T#2>) is not applicable
      (cannot infer type-variable(s) T#2
        (actual and formal argument lists differ in length))
  where T#1,E,T#2 are type-variables:
    T#1 extends Object,Comparable<? super T#1> declared in method <T#1>min(Collection<? extends T#1>)
    E extends Object declared in method <E>of(E,E)
    T#2 extends Object declared in method <T#2>min(Collection<? extends T#2>,Comparator<? super T#2>)
Comment 5 Svata Dedic 2017-05-17 08:36:31 UTC
This is a javac error, and it's IMHO intentional. Note that NetBeans 8.2 bundles half-baked JDK9 compiler, so if NB produces an error the official JDK8 does not, JDK9 is very likely to report the same error.

I suggest to follow advices in the linked discussion or the javadoc page linked in from there (http://docs.oracle.com/javaee/6/api/javax/persistence/criteria/Path.html#get%28java.lang.String%29) and use parametrized method call to supply the ncessary types.

Lowering the priority, moving to the correct component. IMHO it is a WONTFIX/INVALID
Comment 6 coladict 2017-08-01 07:55:55 UTC
It is most certainly NOT INVALID. This bug was introduced in 8.2 when it wasn't there in 8.1. When the IDE tells people there's an ambiguous error, they will try to fix it in and probably waste a lot of time trying to do so, without trying to compile, because they don't expect it to work. The tools are supposed to help our work, not hinder it.

As other examples have shown, this is not limited to the JPA scenarios where you can work around it by using parametrized queries.
Comment 7 pallinger 2017-10-31 14:17:13 UTC
I can also reproduce the bug on ubuntu 16.4 with OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-2ubuntu1.16.04.3-b11), NetBeans IDE 8.2 (Build 201609300101). 
I also agree that while functionally seemingly harmless, this bug is highly confusing.