Drools Error : Unable to find #positional field - drools

I created a drool file PersonTotalAccountsBalance.drl as below. I am beginner in the rules engine world.
package com.auhuman.rules;
import com.auhuman.Person;
import com.auhuman.Account;
function float getTotalBalance(Person person) {
float totalBalance = 0;
for (Account account : person.getAccounts()){
totalBalance += account.getBalance();
}
return totalBalance;
}
rule "PersonTotalAccountsBalance"
when
$node : Person(active == true)
then
float totalBalance = getTotalBalance($node)
modify($node) {
setTotalBalance(totalBalance);
}
end
Upon compile I am getting below error
Unable to compile the file: PersonTotalAccountsBalance.drl. Errors = [Unable to find #positional field 0 for class Person
: [Rule name='PersonTotalAccountsBalance']
]

Although this question is very old:
I had the same error message but I was working with decision tables in xls (excel) format. The table looked like this:
Note that $order:Order is in a merged cell goes across both the CONDITION and the ACTION columns. That cell is only allowed to be above CONDITION tables, not the ACTION tables. After unmerging I didn't get the error anymore:
I got a very similar error when defining the wrong values in the ACTION column for setting an attribute. When using values without quotes for a String attribute in the model Order I got the following error:
Unable to get KieModule, Errors Existed: Error Messages:
Message [id=1, kieBase=defaultKieBase, level=ERROR, path=status_rules/status.xls, line=21, column=0
text=Rule Compilation error The method setNextStatus(String) in the type Order is not applicable for the arguments (int)]
Message [id=2, kieBase=defaultKieBase, level=ERROR, path=status_rules/status.xls, line=5, column=0
text=Rule Compilation error The method setNextStatus(String) in the type Order is not applicable for the arguments (int)]
Message [id=3, kieBase=defaultKieBase, level=ERROR, path=status_rules/status.xls, line=13, column=0
text=Rule Compilation error The method setNextStatus(String) in the type Order is not applicable for the arguments (int)]
However in this case the error message was more precise.

Related

AOSP build: Api check failed when replacing public java files under frameworks/base/core with prebuilt .jar

I am compiling Android 8.1 AOSP, I want to remove any specified java files under frameworks/base/services and frameworks/base/core, and build the removed java files into .jar libraries, then add the library to framework to make it compile successfully. I succeeded in frameworks/base/services, but failed with API check when do it in frameworks/base/core.
What I did:
Disable JACK compile tool, modify file build/make/core/combo/javac.mk
ANDROID_COMPILE_WITH_JACK := false
Copy frameworks/base/core/java/android/app/ActivityManager.java to frameworks/base/core/mytest/core/java/ActivityManager.java
Create frameworks/base/core/mytest/Android.mk:
include $(CLEAR_VARS)
LOCAL_MODULE := frameworks.base.core.mytest
LOCAL_SRC_FILES += \
$(call all-java-files-under,core/java)
# depends on it to make compilition success
LOCAL_JAVA_LIBRARIES := services
include $(BUILD_STATIC_JAVA_LIBRARY)
Run command: mmm frameworks/base/core/mytest
Then it will generat a .jar file: out/target/product/mydevice/obj/JAVA_LIBRARIES/frameworks.base.core.mytest_intermediates/javalib.jar, copy it into prebuilt/mylibs/
Create prebuilt/mylibs/Android.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
# my lib is named as 'myam'
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES += myam:javalib.jar
include $(BUILD_MULTI_PREBUILT)
Modify frameworks/base/Android.mk, in framework module, add line:
LOCAL_MODULE := framework
# add my lib to framework.jar
LOCAL_STATIC_JAVA_LIBRARIES += myam
REMOVE the original file: rm frameworks/base/core/java/android/app/ActivityManager.java
Run make command to build the AOSP project, I got the error log:
javadoc: error - In doclet class com.google.doclava.Doclava, method start has thrown an exception java.lang.reflect.InvocationTargetException
java.lang.IllegalArgumentException: Unable to find ActivityManager.java. This is usually because doclava has been asked to generate stubs for a file that isn't present in the list of input source files but exists in the input classpath.
at com.google.doclava.Stubs.parseLicenseHeader(Stubs.java:656)
at com.google.doclava.Stubs.writeClassFile(Stubs.java:635)
Where throws the exception is in external/doclava/src/com/google/doclava/Stubs.java:
private static String parseLicenseHeader(/* #Nonnull */ SourcePositionInfo positionInfo) {
//...
File sourceFile = new File(positionInfo.file);
if (!sourceFile.exists()) {
throw new IllegalArgumentException("Unable to find " + sourceFile +
". This is usually because doclava has been asked to generate stubs for a file " +
"that isn't present in the list of input source files but exists in the input " +
"classpath.");
}
Since the source file has been removed, so I specified the source file path to a Stub file that generated by a previous successful built:
out/target/common/obj/JAVA_LIBRARIES/android_system_stubs_current_intermediates/src/android/app/ActivityManager.java, copy it to /data1/myAOSProot/generated/stubs/ActivityManager.java,
private static String parseLicenseHeader(/* #Nonnull */ SourcePositionInfo positionInfo) {
//...
File sourceFile = new File(positionInfo.file);
if (!sourceFile.exists()) {
// As it can't find the source file, I specified it as below:
if (positionInfo.file.equals("ActivityManager.java") || positionInfo.file.endsWith("/ActivityManager.java")) {
sourceFile = new File("/data1/myAOSProot/generated/stubs/ActivityManager.java");
} else {
throw new IllegalArgumentException("Unable to find " + sourceFile +
". This is usually because doclava has been asked to generate stubs for a file " +
"that isn't present in the list of input source files but exists in the input " +
"classpath.");
}
}
But I got a new error:
ActivityManager.java:0: warning: Method android.app.ActivityManager.TaskSnapshot.getSnapshot returns unavailable type GraphicBuffer m.position? ActivityManager.java [110]
ActivityManager.java:0: warning: Method android.app.ActivityManager.getGrantedUriPermissions returns unavailable type ParceledListSlice m.position? ActivityManager.java [110]
ActivityManager.java:0: warning: Method android.app.ActivityManager.getService returns unavailable type IActivityManager m.position? ActivityManager.java [110]
ActivityManager.java:0: warning: Parameter of unavailable type android.content.pm.IPackageDataObserver in android.app.ActivityManager.clearApplicationUserData() [110]
out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/core/java/android/app/IActivityManager.java:10691: warning: Parameter of hidden type android.app.ContentProviderHolder in android.app.IActivityManager.publishContentProviders() [110]
out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/core/java/android/app/IApplicationThread.java:2321: warning: Parameter of hidden type android.app.ResultInfo in android.app.IApplicationThread.scheduleSendResult() [110]
out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/core/java/android/app/IApplicationThread.java:2322: warning: Parameter of hidden type android.app.ResultInfo in android.app.IApplicationThread.scheduleLaunchActivity() [110]
out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/core/java/android/app/IApplicationThread.java:2341: warning: Parameter of hidden type android.app.ResultInfo in android.app.IApplicationThread.scheduleRelaunchActivity() [110]
This is because of the #hide or #removed comments in GraphicBuffer.java etc., I try ignoring the errors by comment the codes reporting error in external/doclava/src/com/google/doclava/Errors.java:
public static void error(Error error, SourcePositionInfo where, String text) {
// all commented
}
But still, another error:
out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/src/android/content/pm/ParceledListSlice.java:19: error: cannot find symbol
extends android.content.pm.BaseParceledListSlice<T>
^
symbol: class BaseParceledListSlice
location: package android.content.pm
out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/src/android/app/IApplicationThread.java:13: error: cannot find symbol
public abstract void scheduleSendResult(android.os.IBinder token, java.util.List<android.app.ResultInfo> results) throws android.os.RemoteException;
^
symbol: class ResultInfo
location: package android.app
out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/src/android/app/IApplicationThread.java:14: error: cannot find symbol
public abstract void scheduleLaunchActivity(android.content.Intent intent, android.os.IBinder token, int ident, android.content.pm.ActivityInfo info, android.content.res.Configuration curConfig, android.content.res.Configuration overrideConfig, android.content.res.CompatibilityInfo compatInfo, java.lang.String referrer, com.android.internal.app.IVoiceInteractor voiceInteractor, int procState, android.os.Bundle state, android.os.PersistableBundle persistentState, java.util.List<android.app.ResultInfo> pendingResults, java.util.List<com.android.internal.content.ReferrerIntent> pendingNewIntents, boolean notResumed, boolean isForward, android.app.ProfilerInfo profilerInfo) throws android.os.RemoteException;
^
symbol: class ResultInfo
location: package android.app
out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/src/android/app/IApplicationThread.java:33: error: cannot find symbol
public abstract void scheduleRelaunchActivity(android.os.IBinder token, java.util.List<android.app.ResultInfo> pendingResults, java.util.List<com.android.internal.content.ReferrerIntent> pendingNewIntents, int configChanges, boolean notResumed, android.content.res.Configuration config, android.content.res.Configuration overrideConfig, boolean preserveWindow) throws android.os.RemoteException;
^
symbol: class ResultInfo
location: package android.app
The files reporting error like out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/src/android/content/pm/ParceledListSlice.java actually is NOT existed in a NORMAL AOSP compiling, and the file it refers like BaseParceledListSlice.java is just under the same directory as ParceledListSlice.java, I am confused why would this error happen.
Did I miss anything or is there a different way to achieve my goal? I just want to replace java files to .jar libraries.
Anyone could help me out? Thanks a lot!

How to log an error with Swiftlog package?

When I am catching a error and want to log it with the official swift logger swiftlog package like this:
do {
try something()
} catch {
logger.error(error.localizedDescription)
}
I get the message "Cannot conversation value of type 'String' to expected argument type 'Logger.Message'
I get a similar message for logger.error(error).
How to do this best?

How to fix RuntimeException: error reading Scala signature of com.snp.utils.DbUtils: error reading Scala signature

I have defined
var status:String = null;
var error_msg:String = null;
try{ status ="Error"; error_msg= "n/a";
}
When I place my method in DbUtils object and call from my main class it is throwing error, i.e. when calling
DbUtils.writeToCassandraAuditLog(spark, status, error_msg);
it throws below error
2018-10-23 14:03:37 ERROR java.lang.RuntimeException: error reading Scala signature of com.snp.utils.DbUtils: error reading Scala signature of org.apache.spark.sql.package: assertion failed: unsafe symbol Unstable (child of <none>) in runtime reflection universe
at scala.reflect.internal.pickling.UnPickler.unpickle(UnPickler.scala:46)
But when I place/define the methods in my main class/object it is working fine.
writeToCassandraAuditLog(spark, status, error_msg);
How to fix this issue?

Unknown error on VDM++ toolbox lite

I'm doing VDM++ on VDM++ toolbox lite and below is my example code:
class Course
types
public study :: numsubj : nat1
sem : nat1;
public subjpersem = nat1;
operations
public getsubj:nat1 * nat1 ==>study
getsubj(numsubj,sem) == (
subjpersem := numsubj/sem;
);
end Course
I tried to run the code. Succeeded creating the object but when I run print getsubj(10,2), it returns error Run-Time Error 120: Unknown state component
Can somebody help me thank you in advance
In Overture/VDMJ, this spec gives two type checking errors. Do these not appear in VDMTools?
Error 3247: Symbol 'subjpersem' is not an updatable variable in 'Course' (test.vpp) at line 9:5
Error 3027: Operation returns unexpected type in 'Course' (test.vpp) at line 7:8
Actual: ()
Expected: study
Type checked 1 class in 0.119 secs. Found 2 type errors

orientdb db.save "object is ambiguous" error

I'm using release orientdb-community-2.1.9.
Following example in docs (http://orientdb.com/docs/2.1/Functions.html)
I tried:
return db.save({
"#class": "V",
log: 'test'
});
And I've got this error:
Error on parsing script at position #0: Error on execution of the script\nScript: test\n------^\nsun.org.mozilla.javascript.EvaluatorException: The choice of Java method com.orientechnologies.orient.core.command.script.OScriptDocumentDatabaseWrapper.save matching JavaScript argument types (object) is ambiguous; candidate methods are: \n class com.orientechnologies.orient.core.record.impl.ODocument save(com.orientechnologies.orient.core.record.ORecord)\n class com.orientechnologies.orient.core.record.impl.ODocument save(java.util.Map) (#360) in at line number 360\nThe choice of Java method com.orientechnologies.orient.core.command.script.OScriptDocumentDatabaseWrapper.save matching JavaScript argument types (object) is ambiguous; candidate methods are: \n class com.orientechnologies.orient.core.record.impl.ODocument save(com.orientechnologies.orient.core.record.ORecord)\n class com.orientechnologies.orient.core.record.impl.ODocument save(java.util.Map) (#360)
How can I correct this ambiguity?
Thanks
Luca