i have a piece of code
for(Importer user : getUserRecords(query.getResultList())){...
where the called function is
protected List<Importer> getUserRecords(List<Object[]> users){
List<Importer> result = new ArrayList<Importer>();
for (Object[] obj : users) {
UserRecord userRecord = (UserRecord) obj[0];
...
result.add(userRecord);
} return result;
everything is ok in eclipse and in maven when i use ibm java 1.6.
When i switch to oracle java 1.8 in eclipse it is also ok but maven compiler complains that the getUserRecords returns wrong types
incompatible types: java.lang.Object cannot be converted to com.volvo.cmslms.database.entities.importer.Importer
however when i change the code to
List<Importer> userImporters = getUserRecords(query.getResultList());
for(Importer user : userImporters){...
everything is ok everywhere. I dont have a clue what the issue is here.
Related
I am trying to handle keycloak's Custom User Storage SPI with the example provided.
https://github.com/keycloak/keycloak-quickstarts/tree/latest/user-storage-simple
When launching mvn clean install wildfly:deploy while Keycloak is launched, I get 3 errors from this file PropertyFileUserStorageProvider.java:
variable cred of type org.keycloak.models.UserCredentialModel cannot find symbol (method getValue())
I don't get why I am facing those errors.
They also use this getValue method in the documentation.
https://www.keycloak.org/docs/latest/server_development/index.html#_user-storage-spi
Java & Maven versions
Java Version 1.8.0_20
Apache Maven 3.6.2
Thanks for your help
UserCredentialModel class has changed a lot in the latest Keycloak release 8.0.0
It looks like the "quick start examples" need some fixes to work with this release
Something like :
#Override
public boolean isValid(RealmModel realm, UserModel user, CredentialInput input) {
// No need to check input is of type UserCredentialModel since there no need to cast it anymore
if (!supportsCredentialType(input.getType())) return false;
String password = properties.getProperty(user.getUsername());
if (password == null) return false;
// Input Password can now be obtained using the getChallengeResponse() method of the CredentialInput type
return password.equals(input.getChallengeResponse());
}
Hope this will help.
Regards,
I got the following error today:
java.lang.NoSuchMethodError: javax.swing.JList.getSelectedValuesList()Ljava/util/List;
We have some customers still using old java6 versions out there. (Some old posready/embedded-version of windows that doesn't accept installing 1.8 directly..)
Therefore I use compiler compliance level 1.6 in eclipse. However, after an upgrade of our software, some customers reported errors/freezing. I logged in, and found the following error:
java.lang.NoSuchMethodError: getSelectedValuesList()Ljava/util/List;
It appears that this particular JList method in was introduced in 1.7, and I have started using it since getSelectedValues() is deprecated.
But this breaks things on 1.6, since the method does not exist in 1.6.
I have made a workaround, instead of calling getSelectedValuesList() I now call the following method:
public static <E> java.util.List<E> getSelectedValuesList(javax.swing.JList<E> l) {
try {
return l.getSelectedValuesList();
}catch(java.lang.NoSuchMethodError err) {
ArrayList<E> v = new ArrayList<E>();
Object[] oo = l.getSelectedValues();
for (Object o : oo) {
v.add((E)o);
}
return v;
}
}
This seems to work ok. But my question is, since source level is 1.6, how do I detect similar errors? Since I don't even have 1.6 installed, how can I know for sure that all my swing methods that I call actually works in 1.6? I don't want to introduce yet another bug later on. :-)
I have a piece of code that has to be JDK 1.4 compliant. And below is a snippet which gets a runtime exception.
BaseDocument baseDocument = new BaseDocument();
baseDocument.setGuid("{somethinghere}");
List document = new ArrayList();
document.add(baseDocument);//runtime error
Exception:
java.lang.ClassCastException: [Ljava.lang.Object; incompatible with [Lcom.company.base.BaseDocument;
I don't understand why we cant cast it to a java Object(since Object is the parent class of all Classes in java).
Im using IBM JDK version 1.7 with Eclipse compiler settings set to JDK 1.4
Please explain what mistake I'm doing here. I know generics is the standard, but it has to be JDK 1.4 compliant :(
Thanks in advance!
Actually, the message says:
[Ljava.lang.Object; incompatible with [Lcom.company.base.BaseDocument;
The [ characters are very important. Apparently, something is attempting cast something of type Object[] to BaseDocument[]; i.e. you are dealing with array types here.
However, I have no idea what is actually causing the problem here, because (on the face of it) there should be no instances of BaseDocument[] in the code you have posted. Furthermore, I don't believe your claim that that exception is thrown at that line. Here is the source code of the ArrayList.add method (Java 6 version):
private transient Object[] elementData;
public boolean add(E e) {
ensureCapacity(size + 1); // Increments modCount!!
elementData[size++] = e;
return true;
}
An assignment of a reference into an object array (Object[]) does not entail any runtime type-checks, and cannot throw a ClassCastException.
If you showed us a complete stacktrace, it would be easier to diagnose.
I have this piece of code which worked in Java 6
if(false==sess.getAttribute("admin") || null==sess.getAttribute("admin"))
{
res.sendRedirect("/myapp/login.jsp?errmsg=You must log in as an administrator to manage resources");
return;
}
I want to familiarize myself with the new features of Java 7 and what it offers new in javaee hence I upgraded netbeans to 7.4 and jdk 7u45.
My project opened successfully however the file with this code is marked as a java class with an error by netbeans. Running the project I get the error
java.lang.RuntimeException: Uncompilable source code - incomparable types: boolean and java.lang.Object
What I want to ask is why this worked in java6 and doesn't work in java7
FYI HttpSession sess = req.getSession();
HttpSession.getAttribute returns an Object.
Change the line to (Boolean.FALSE==sess.getAtrribute)
Looks like autoboxing (boolean to Boolean) has changed in Java.
Unfortunately I cannot reproduce your error. I have seen a similar error message in the same Netbeans 7.4/jdk 7u45.
My code:
if (true == evt.getNewValue())
(where evt is a PropertyChangeEvent)
The message in Netbeans (when I hover over the red cross left to the statement) says "incomparable types: boolean and Object". Notice the difference with your message: the missing "java/lang" before Object.
And even stranger: my code compiles without any problem.
Compiler options in Netbeans are: "-version -Xlint:unchecked -Xlint:deprecation"
You should try with
if(false==(Boolean)sess.getAttribute("admin") || null==sess.getAttribute("admin"))
{
res.sendRedirect("/myapp/login.jsp?errmsg=You must log in as an administrator to manage resources");
return;
}
getAttribute probably returns either an Object or a boolean. If it returns a boolean, then null==getAttrubute will not work and if it returns an Object then false==getAttribute will fail.
I am using flex 4.5.1, JDK 1.6 , BlazeDS v4.0.1(21287) on a complex project : Cairngorm is used most of the time but Swiz is also used in imported swc.
I was able to make remote calls to java without any problems in many cases but not now.
I am getting an error in my flex code when I iterate through a collection received from my java server (RemoteCall):
Java function is
List< FundGenderDto > getFundGenders()
My error is :
TypeError: Error #1034: Type Coercion failed: cannot convert Object#a245779 to com.xxx.apps.fnr.vo.fund.FundGenderVO
In debug I see that I reveive an ArrayCollection of Objects containing sub values specifics to a FundGenderVO/FundGenderDto
The actionscript code where it occurs :
for each ( var gender : FundGenderVO in list ){ // do something }
My FundGenderVO.as is :
package com.xxx.apps.fnr.vo.fund
{
import mx.collections.ArrayCollection;
[RemoteClass(alias="com.xxx.apps.fnr.service.dto.FundGenderDto")]
[Bindable]
public class FundGenderVO extends AbstractVO {
public var id:int;
public var type:String;
public var fundTypes: ArrayCollection = new ArrayCollection();
public function FundGenderVO(){
super();
}
}
}
I have activated BlazeDS full trace to see that I receive the appropriate : com.xxx.apps.fnr.service.dto.FundGenderDto.
So really the same as in my "RemoteClass"
[BlazeDS]Result: 'java.util.ArrayList (Collection size:2)
[0] = com.xxx.apps.fnr.service.dto.FundGenderDto#99f98a[type=Long Only,fundTypes=[com.xxx.apps.fnr.service.dto.FundTypeDto#60540d[type=Umbrella,investable=false,id=100], com.xxx.apps.fnr.service.dto.FundTypeDto#2e2f02[type=Sub-Fund,investable=false,id=300]],id=0]
// second object ...
I tried to check if I didn't make a stupid error with http://www.webappsolution.com/wordpress/tag/remoteclass-metadata/
Is there a way to better diagnose what's going on ?
What am i possibly doing wrong or stupid ?