I am upgrading a legacy application from Java 8 to Java 11 (Oracle Version) and having issue while getting the corbaloc reference.
I have read below
articles here and here that specifies that CORBA support is removed form JAVA 11 and with the help of Glassfish Corba I can use the packages again.
The issue I am facing is with below function call
((com.sun.corba.se.spi.orb.ORB) orb.orb()).register_initial_reference(idStr, ref);
In Eclipse the Error is ORB cannot be resolved to a type.
As I know we should not use any package related to sun but this is old code and not sure about the replacement.
I have changed the package from com.sun.corba.se.spi.orb.ORB to org.omg.CORBA.ORB but the method register_initial_reference(idStr, ref) is not found.
I am not sure what needs to be changed or any example that will help to get the possible alternate change. Any guide or help is highly appreciated. Even I have almost NO idea about CORBA and very less examples are available.
Below is the function that starts the service
final byte[] id = "\u00ffPNS_Service\u0000PNS_Study".getBytes();
final String idStr = new String(id);
final Policy[] policies = new Policy[] {
root.create_lifespan_policy(LifespanPolicyValue.PERSISTENT) };
final POA poa = root.create_POA("PNS_Service",root.the_POAManager(),policies);
poa.the_POAManager().activate();
poa.activate_object(studyService);
final org.omg.CORBA.Object ref = poa.servant_to_reference(studyService);
((com.sun.corba.se.spi.orb.ORB) orb.orb()).register_initial_reference(idStr , ref);```
I am moving my code from JDK 8 to Open JDK 12. While doing so, I am facing following issue :
java.lang.NoSuchFieldException: scl
while trying to call ClassLoader.class.getDeclaredField("scl"). This was working fine in Java 8 but no longer works in newer Java versions.
I did some findings and believe it has got to do with the way working of reflection and use of internal Java packages have changed since Java 8.
Set<URL> classLoaderUrls = computeClassLoaderUrls();
ClassLoader bootstrapClassLoader = ClassLoader.getSystemClassLoader().getParent();
this.classLoader = new URLClassLoader(classLoaderUrls.toArray(new URL[classLoaderUrls.size()]), bootstrapClassLoader);
Field systemClassLoaderField = ClassLoader.class.getDeclaredField("scl");
systemClassLoaderField.setAccessible(true);
this.initialSystemClassLoader = (ClassLoader) systemClassLoaderField.get(null);
systemClassLoaderField.set(null, this.classLoader);
I want to know , if the way to access these classloader and its fields has changed or should I use some other field instead of scl. Thanks
What am I doing?
I am writing a data analysis program in Java which relies on R´s arulesViz library to mine association rules.
What do I want?
My purpose is to store the rules in a String variable in Java so that I can process them later.
How does it work?
The code works using a combination of String.format and eval Java and RJava instructions respectively, being its behavior summarized as:
Given properly formatted Java data structures, creates a data frame in R.
Formats the recently created data frame into a transaction list using the arules library.
Runs the apriori algorithm with the transaction list and some necessary values passed as parameter.
Reorders the generated association rules.
Given that the association rules cannot be printed, they are written to the standard output with R´s write method, capture the output and store it in a variable. We have converted the association rules into a string variable.
We return the string.
The code is the following:
// Step 1
Rutils.rengine.eval("dataFrame <- data.frame(as.factor(c(\"Red\", \"Blue\", \"Yellow\", \"Blue\", \"Yellow\")), as.factor(c(\"Big\", \"Small\", \"Small\", \"Big\", \"Tiny\")), as.factor(c(\"Heavy\", \"Light\", \"Light\", \"Heavy\", \"Heavy\")))");
//Step 2
Rutils.rengine.eval("transList <- as(dataFrame, 'transactions')");
//Step 3
Rutils.rengine.eval(String.format("info <- apriori(transList, parameter = list(supp = %f, conf = %f, maxlen = 2))", supportThreshold, confidenceThreshold));
// Step 4
Rutils.rengine.eval("orderedRules <- sort(info, by = c('count', 'lift'), order = FALSE)");
// Step 5
REXP res = Rutils.rengine.eval("rulesAsString <- paste(capture.output(write(orderedRules, file = stdout(), sep = ',', quote = TRUE, row.names = FALSE, col.names = FALSE)), collapse='\n')");
// Step 6
return res.asString().replaceAll("'", "");
What´s wrong?
Running the code in Linux Will work perfectly, but when I try to run it in Windows, I get the following error referring to the return line:
Exception in thread "main" java.lang.NullPointerException
This is a common error I have whenever the R code generates a null result and passes it to Java. There´s no way to syntax check the R code inside Java, so whenever it´s wrong, this error message appears.
However, when I run the R code in brackets in the R command line in Windows, it works flawlessly, so both the syntax and the data flow are OK.
Technical information
In Linux, I am using R with OpenJDK 10.
In Windows, I am currently using Oracle´s latest JDK release, but trying to run the program with OpenJDK 12 for Windows does not solve anything.
Everything is 64 bits.
The IDE used in both operating systems is IntelliJ IDEA 2019.
Screenshots
Linux run configuration:
Windows run configuration:
I have a strange memory problem with Java library of Z3 which I couldn't figure where the problem is. Oddly, I can't reproduce the problem on a Windows machine where I have Java 7 (I most probably have slightly older version of Z3 there though). The problem occurs on a MacOSx 10.6.8 with Java 6 and Z3 v4.3.2. I have an application that uses Z3 for analysis. I tracked the following piece of code as the (initial) source of the problem:
Symbol eNames = con.mkSymbol(domainName);
Symbol[] symbols = new Symbol[values.length];
for (int i = 0; i < values.length; i++) symbols[i] = con.mkSymbol(values[i]);
System.out.println("Before ENUMSORT");
//EnumSort eSort = con.mkEnumSort(domainName, values);
EnumSort eSort = con.mkEnumSort(eNames,symbols);
System.out.println("After ENUM SORT ...");
When I run the application I get the following after "Before ENUMSORT" is printed:
java(55938,0x100501000) malloc: *** error for object 0x10200f1b8: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
I know this is not a good way of debugging especially when there is a memory problem but it is very difficult to debug the code since it originates from JNI. When I look at the Z3 code here (https://github.com/Z3Prover/z3/blob/master/src/api/api_datatype.cpp) I couldn't figure what the source of the problem is. I assume that the method Z3_mk_enumeration_sort is called from mkEnumSort method in Java. When I change the call of mkEnumSort in my code to a form like
EnumSort eSort = con.mkEnumSort(domainName,new String[]{"X","Y"});
the problem seems gone. What do you think, what could be the source of the problem?
Any help is highly appreciated.
In cpp file I have std::round(double)
Please can I know the equivalent code in Java
Edit: I am already using java.lang.Math.round(double) and getting match in 99% cases. But in some places iam getting mismatch. For example:
std::round(4816.5058) = 4816 and Math.round(4816.5058) = 4817
std::round(4466.49996) = 4467 and Math.round(4466.49997) = 4466
java.lang.Math.round(double)