Drools 6.4.0 fails with error uncomparable values - java

I have java class Fact as below
class AssertionFact {
String name;
Object value;
}
When i was using Drools 5.2 & rule as below it was working perfectly fine.
AssertionFact(
object > 100,
name == "testName"
)
But now when i have upgraded my drools version to 6.4.0 & JDK 1.8 I am getting below error for same rules.
Caused by: java.lang.RuntimeException: uncomparable values <<TESTVALUE>> and <<100.0>>
at org.mvel2.math.MathProcessor.doOperationNonNumeric(MathProcessor.java:274)
at org.mvel2.math.MathProcessor._doOperations(MathProcessor.java:234)
at org.mvel2.math.MathProcessor.doOperations(MathProcessor.java:79)
at org.mvel2.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:117)
at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
at org.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123)
at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119)
at org.mvel2.MVEL.executeExpression(MVEL.java:929)
at org.drools.core.util.MVELSafeHelper$RawMVELEvaluator.executeExpression(MVELSafeHelper.java:496)

Related

Field of type "error.NonExistentClass" cannot be an #Index (Realm java)

My app complains about a field "OrderId" which is defined in a library that I maintain, which was recently upgraded.
This occurs in the KaptWithoutKotlinc task.
Field "orderId" of type "error.NonExistentClass" cannot be an #Index
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction
> java.lang.reflect.InvocationTargetException (no error message)
Realm-java version: 6.1.0.
In my app:
open class Metadata : RealmObject() {
#PrimaryKey
var id: String = "1234"
#Index
var orderId: OrderId = 4
In my library:
Definitions.kt
typealias OrderId = Int
I have already tried the following:
kapt {
correctErrorTypes true
}
This was not a Realm error. Downgrading the Kotlin-Gradle plugin from 1.6.0 to 1.5.0 fixed the issue. Something about upgrading Kotlin in my library caused the typealias OrderId definition to be missing from the generated Definitions.class file that my app was pulling in from the library (I inspected this file by going to Android Studio > External Libraries> com.mylibrary > Definitions.class and seeing that OrderId was not defined there). After downgrading typealias to be present in Definitions.class, my app could resolve the OrderId typealias, and then Realm no longer considered OrderId an invalid #Index field.
org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0

Error obj.javaClass.`package` when running tests after corda upgrade

I just upgraded from corda 3.3 to 4.0 and then all my contract and flow tests started to fail. these are failing in those lines where I'm defining transactions (transaction builder objects, when adding oputput and input satates).
ledger(ledgerServices, l -> {
l.transaction(tx -> {
tx.input(fooContract.foo_CONTRACT_ID, fooContractState);
tx.command(Arrays.asList(node1.getPublicKey(),
node2.getPublicKey()),
new fooContract.Commands.dummyCommand());
// Correct type.
return tx.verifies();
}
}
I get the following error:
obj.javaClass.package must not be null
It was a problem caused when a TransactionBuilder was trying to find a StatePointer inside the transaction and a package name was null (The logical to find a package was wrong, because It was considering and calling something that was null in its origin). Remindering you that StatePointer was released only Corda Platform Open Source 4.0.
I recommend you upgrade your CorDapp to the version Corda 4.1 because it was fixed on March 7, 2019 and released only in Corda 4.1.
Your log should be logging something like this:
obj.javaClass.package must not be null
java.lang.IllegalStateException: obj.javaClass.package must not be null
at net.corda.core.internal.StatePointerSearch.handleObject(StatePointerSearch.kt:75)
at net.corda.core.internal.StatePointerSearch.handleField(StatePointerSearch.kt:85)
at net.corda.core.internal.StatePointerSearch.search(StatePointerSearch.kt:92)
at net.corda.core.transactions.TransactionBuilder.resolveStatePointers(TransactionBuilder.kt:494)
at net.corda.core.transactions.TransactionBuilder.addOutputState(TransactionBuilder.kt:568)
For more information:
https://github.com/corda/corda/commits/release/4.1/core/src/main/kotlin/net/corda/core/internal/StatePointerSearch.kt
Looking at commit realized on Mar 7, 2019, the handleObject(obj: Any?) method was trying to get an attribute called 'name' in packageName attribute, but the 'name' atributte is null.

RuntimeException: Could not extract key occurs only on runtime environment

I am running flink locally on my machine , I am getting the exception below when reading from kafka topic. when running from the ide (intellij) it is running perfectly. however when I deploy my jar to flink runtime environment (locally) using
/bin/flink run ~MyApp-1.0-SNAPSHOT.jar
my class looks like this
case class Foo(id: String, value: String, timestamp: Long, counter: Int)
I am getting this exception
java.lang.RuntimeException: Could not extract key from Foo(some-uuid,some-text,1540348398,1)
at org.apache.flink.streaming.runtime.io.RecordWriterOutput.pushToRecordWriter(RecordWriterOutput.java:110)
at org.apache.flink.streaming.runtime.io.RecordWriterOutput.collect(RecordWriterOutput.java:89)
at org.apache.flink.streaming.runtime.io.RecordWriterOutput.collect(RecordWriterOutput.java:45)
at org.apache.flink.streaming.api.operators.AbstractStreamOperator$CountingOutput.collect(AbstractStreamOperator.java:689)
at org.apache.flink.streaming.api.operators.AbstractStreamOperator$CountingOutput.collect(AbstractStreamOperator.java:667)
at org.apache.flink.streaming.api.operators.StreamFilter.processElement(StreamFilter.java:40)
at org.apache.flink.streaming.runtime.tasks.OperatorChain$CopyingChainingOutput.pushToOperator(OperatorChain.java:579)
at org.apache.flink.streaming.runtime.tasks.OperatorChain$CopyingChainingOutput.collect(OperatorChain.java:554)
at org.apache.flink.streaming.runtime.tasks.OperatorChain$CopyingChainingOutput.collect(OperatorChain.java:534)
at org.apache.flink.streaming.api.operators.AbstractStreamOperator$CountingOutput.collect(AbstractStreamOperator.java:689)
at org.apache.flink.streaming.api.operators.AbstractStreamOperator$CountingOutput.collect(AbstractStreamOperator.java:667)
at org.apache.flink.streaming.api.operators.StreamSourceContexts$NonTimestampContext.collect(StreamSourceContexts.java:104)
at org.apache.flink.streaming.api.operators.StreamSourceContexts$NonTimestampContext.collectWithTimestamp(StreamSourceContexts.java:111)
at org.apache.flink.streaming.connectors.kafka.internals.AbstractFetcher.emitRecordWithTimestamp(AbstractFetcher.java:398)
at org.apache.flink.streaming.connectors.kafka.internal.Kafka010Fetcher.emitRecord(Kafka010Fetcher.java:89)
at org.apache.flink.streaming.connectors.kafka.internal.Kafka09Fetcher.runFetchLoop(Kafka09Fetcher.java:154)
at org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumerBase.run(FlinkKafkaConsumerBase.java:738)
at org.apache.flink.streaming.api.operators.StreamSource.run(StreamSource.java:87)
at org.apache.flink.streaming.api.operators.StreamSource.run(StreamSource.java:56)
at org.apache.flink.streaming.runtime.tasks.SourceStreamTask.run(SourceStreamTask.java:99)
at org.apache.flink.streaming.runtime.tasks.StreamTask.invoke(StreamTask.java:300)
at org.apache.flink.runtime.taskmanager.Task.run(Task.java:711)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: Could not extract key from Foo("some-uuid","text",1540348398,1)
at org.apache.flink.streaming.runtime.partitioner.KeyGroupStreamPartitioner.selectChannels(KeyGroupStreamPartitioner.java:61)
at org.apache.flink.streaming.runtime.partitioner.KeyGroupStreamPartitioner.selectChannels(KeyGroupStreamPartitioner.java:32)
at org.apache.flink.runtime.io.network.api.writer.RecordWriter.emit(RecordWriter.java:106)
at org.apache.flink.streaming.runtime.io.StreamRecordWriter.emit(StreamRecordWriter.java:81)
at org.apache.flink.streaming.runtime.io.RecordWriterOutput.pushToRecordWriter(RecordWriterOutput.java:107)
... 22 more
Caused by: java.lang.NullPointerException
at com.bluevoyant.StreamingJob$$anonfun$3.apply(StreamingJob.scala:41)
at com.bluevoyant.StreamingJob$$anonfun$3.apply(StreamingJob.scala:40)
at org.apache.flink.streaming.api.scala.DataStream$$anon$2.getKey(DataStream.scala:411)
at org.apache.flink.streaming.runtime.partitioner.KeyGroupStreamPartitioner.selectChannels(KeyGroupStreamPartitioner.java:59)
... 26 more
my key partition is simple (partitionFactor = some number)
env.addSource(kafkaConsumer)
.filter(_.id != null)
.keyBy{ r =>
val h = fastHash(r.id) % partitionFactor
math.abs(h)
}
.map(...)
again, this happens only on runtime not when I run it from intellij
this so frustrating, any advice ?

(java string concatenation)How come this is giving this exception?

this is my simple code.
class atmPin{
public static void main(String[] args) {
int x = 0;
System.out.println("hi there"+x);
}
}
When i run it i get this exception errors.
java atmPin
Exception in thread "main" java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: java/lang/invoke/StringConcatFactory
at atmPin.main(atmPin.java:6)
Caused by: java.lang.NoClassDefFoundError: java/lang/invoke/StringConcatFactory
... 1 more
Caused by: java.lang.ClassNotFoundException: java.lang.invoke.StringConcatFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
is this something to do with java version? i have no idea why is it happening. this is such a simple thing. :(
getting the same kind of exception even with strings.
eg.
String x = "";
x += "a";
java.lang.invoke.StringConcatFactory is a class which appeared in Java 9 in order to implement JEP 280 (Indify String Concatenation) which changes behaviour of javac compiler so that it uses invokedynamic instructon together with the given class for string concatentaion. So the reason for this error most probably is compiling using javac from JDK 9 or later while running this code under Java 8 or less (or, with much less chance, using custom java runtime).
In order to solve it another version of compiler might be used or another version may be specified to the compiler or another JRE should be used for running the compiled class(es).

IncompatibleClassChangeError in Java

After learning Lambda Expressions in Java, I tried to practice some simple examples. But in my first example only I am getting the following error.
Exception in thread "main" java.lang.IncompatibleClassChangeError
at java.lang.invoke.MethodHandleNatives.linkMethodHandleConstant(MethodHandleNatives.java:384)
at com.example.lambda.HelloLambda.main(HelloLambda.java:15)
Caused by: java.lang.NoSuchMethodException: no such method: java.lang.invoke.LambdaMetafactory.metaFactory(Lookup,String,MethodType,MethodHandle,MethodHandle,MethodType)CallSite/invokeStatic
at java.lang.invoke.MemberName.makeAccessException(MemberName.java:763)
at java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:880)
at java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:1019)
at java.lang.invoke.MethodHandles$Lookup.linkMethodHandleConstant(MethodHandles.java:1284)
at java.lang.invoke.MethodHandleNatives.linkMethodHandleConstant(MethodHandleNatives.java:382)
... 1 more
Caused by: java.lang.NoSuchMethodError: java.lang.invoke.LambdaMetafactory.metaFactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
at java.lang.invoke.MethodHandleNatives.resolve(Native Method)
at java.lang.invoke.MemberName$Factory.resolve(MemberName.java:852)
at java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:877)
... 4 more
The error seems an error because of backward compatibility issue. But don't know how to fix this. Many answers in StackOverFlow suggested Recompilation could fix this issue. But still I am getting this error.
My code
package com.example.lambda;
public class HelloLambda {
static String firstname = "ChanSek";
static String lastname = "Nayak";
interface HelloService {
String hello();
}
public static void main(String[] args) {
HelloService helloService =
() -> {String hello="Hello " + firstname + " " + lastname;
return hello;};
System.out.println(helloService.hello());
}
}
The code compiles fine. But running gives the above mentioned error.
I am using JDK1.8.0 snapshot.
Is it possibly because of this?
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=8019635
The way lambdas have been done in Java 8 has changed, very recently (07/2013), in a not backwards compatible way.
If you've somehow managed to compile with a compiler which talks PRE beta 103 lambdas, but are running with a JRE of POST 103 lambdas, you'll have problems.
(The hint for me here is that the metafactory name used to be mixed case, but in java 1.8.0 beta 103 appears to be lower case - you're searching for mixed case, but not finding it.)

Categories

Resources