NoSuchMethodError in neo4j when calling the DatabaseManagementServiceBuilder( path ).build() method - java

I´m devolopping a Java application with neo4j embedded. I don´t know why but it is not possible to build a Database. When I call the the build()-Method in the DatabaseManagementServiceBuilder class I get the following warnings and exeption:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access using Lookup on org.neo4j.internal.unsafe.UnsafeUtil (file:/C:/Users/Benny_Uni/eclipse-workspace/BSc_cocitation_coauthor_graph_B_Birner_9719989/libs/neo4j-community-4.4.13-windows/neo4j-community-4.4.13/lib/neo4j-unsafe-4.4.13.jar) to class java.nio.Buffer
WARNING: Please consider reporting this to the maintainers of org.neo4j.internal.unsafe.UnsafeUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Exception in thread "main" java.lang.NoSuchMethodError: scala.Product.$init$(Lscala/Product;)V
at org.neo4j.cypher.internal.options.CypherVersion$.<init>(CypherQueryOptions.scala:131)
at org.neo4j.cypher.internal.options.CypherVersion$.<clinit>(CypherQueryOptions.scala)
at org.neo4j.cypher.internal.config.CypherConfiguration.<init>(CypherConfiguration.scala:60)
at org.neo4j.cypher.internal.config.CypherConfiguration$.fromConfig(CypherConfiguration.scala:40)
at org.neo4j.cypher.internal.config.CypherConfiguration.fromConfig(CypherConfiguration.scala)
at org.neo4j.fabric.bootstrap.FabricServicesBootstrap.bootstrapServices(FabricServicesBootstrap.java:144)
at org.neo4j.graphdb.factory.module.edition.CommunityEditionModule.bootstrapFabricServices(CommunityEditionModule.java:401)
at org.neo4j.graphdb.facade.DatabaseManagementServiceFactory.build(DatabaseManagementServiceFactory.java:148)
at org.neo4j.dbms.api.DatabaseManagementServiceBuilder.newDatabaseManagementService(DatabaseManagementServiceBuilder.java:101)
at org.neo4j.dbms.api.DatabaseManagementServiceBuilder.build(DatabaseManagementServiceBuilder.java:94)
at HeaderEx.getHeader(HeaderEx.java:37)
at PdfParser.main(PdfParser.java:46)
By this code:
String db_path = System.getProperty("user.dir") + File.separator + "author_database";
File database = new File(db_path);
Path paths = Paths.get(db_path);
managementService = new DatabaseManagementServiceBuilder(paths).build();
graphDb = managementService.database( "DEFAULT_DATABASE_NAME" );
I don´t know, what the problem is. It would be very nice if someone can help me.
I tried to clean the project. I changed the neo4j version. I checkt the configurations rgarding the JDK and JVM. I´m using JDK 11. However, nothing works.

Related

How to fix a jnius.JavaException when using Pyjnius

I am trying to get this example for importing importing TensorFlow in Java to run: https://github.com/deeplearning4j/tf-import
I have managed to get the Java import in Mnist.java to work after some modifications.
However, I am unable to get mnist_jumpy.py to work in order to use the model in DeepLearning4J from Python. I got it run with the modifications below, but I get this exception when loading the model:
log4j:WARN No appenders could be found for logger (org.nd4j.linalg.factory.Nd4jBackend).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.rits.cloning.Cloner (file:/home/micha/.deeplearning4j/pydl4j/pydl4j-1.0.0-SNAPSHOT-cpu-core-datavec-spark2-2.11/pydl4j-1.0.0-SNAPSHOT-bin.jar) to field java.util.TreeSet.m
WARNING: Please consider reporting this to the maintainers of com.rits.cloning.Cloner
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Traceback (most recent call last):
File "/home/micha/Documents/01_work/git/tf_java_import_testing/tf-import/mnist/mnist_jumpy.py", line 17, in <module>
tf_model = jp.TFModel(path + '/mnist.pb')
File "/home/micha/Documents/01_work/git/tf_java_import_testing/tf-import/venv-deepmom/lib/python3.7/site-packages/jumpy/tf_model.py", line 22, in __init__
self.sd = TFGraphMapper.getInstance().importGraph(filepath)
File "jnius/jnius_export_class.pxi", line 906, in jnius.JavaMultipleMethod.__call__
File "jnius/jnius_export_class.pxi", line 638, in jnius.JavaMethod.__call__
File "jnius/jnius_export_class.pxi", line 715, in jnius.JavaMethod.call_method
File "jnius/jnius_utils.pxi", line 93, in jnius.check_exception
jnius.JavaException: JVM exception occurred: class java.lang.String cannot be cast to class org.tensorflow.framework.GraphDef (java.lang.String is in module java.base of loader 'bootstrap'; org.tensorflow.framework.GraphDef is in unnamed module of loader 'app')
From what I understand I am getting the exception jnius.JavaException, because the classes java.lang.String and org.tensorflow.framework.GraphDef live in different contexts, but I don't know how to resolve this (I am completely unfamiliar with jnius).
Any help would be greatly appreciated.
This is my version of mnist_jumpy.py:
import os
try:
# from jnius import autoclass
import jumpy as jp
except KeyError:
os.environ['JDK_HOME'] = "/usr/lib/jvm/java-11-openjdk-amd64"
os.environ['JAVA_HOME'] = "/usr/lib/jvm/java-11-openjdk-amd64"
import jumpy as jp
from scipy import ndimage
# import numpy as np
import os
path = os.path.dirname(os.path.abspath(__file__))
# load tensorflow model
tf_model = jp.TFModel(path + '/mnist.pb')
# load jpg to numpy array
image = ndimage.imread(path + '/img (1).jpg').reshape((1, 28, 28))
# inference - uses nd4j
prediction = tf_model(image) # prediction is a jumpy array
# get label from predction using argmax
label = jp.argmax(prediction.reshape((10,)))
print(label)

Itext Java 11: Illegal reflective access by com.itextpdf.io.source.ByteBufferRandomAccessSource$1

Recently upgraded to Java 11 and began performing a regression check. Currently get an Illegal reflective access error when trying to call com.itextpdf.text.pdf.PdfReader.close. Currently on Itext version 5.5.13 but also tried on itext 7.0.0 and had same issue.
Does anyone have any suggestions on how to fix compatibility issues between Java-11 and Itext?
WARNING: An illegal reflective access operation has occurred WARNING:
Illegal reflective access by
com.itextpdf.io.source.ByteBufferRandomAccessSource$1
(file:...repository/com/itextpdf/io/7.0.0/io-7.0.0.jar) to method
java.nio.DirectByteBuffer.cleaner() WARNING: Please consider reporting
this to the maintainers of
com.itextpdf.io.source.ByteBufferRandomAccessSource$1 WARNING: Use
--illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be
denied in a future release
While I second the comments encouraging you to debug the code and find the root cause (and then submit a pull request), or creating an issue in iText Jira if you are a customer with a support contract (which would raise the priority of the issue), here is a workaround suggestion (that I haven't tested, but I chances are it will work):
Use PdfReader and PdfWriter constructors that accept InputStream and OutputStream, respectively. In this case the code causing the problem should not be invoked. Same thing for all the other cases in which iText interacts with your file system - wrap everything into InputStream/OutputStream, or deal with byte[] arrays.
So this line:
new PdfDocument(new PdfReader(inFilePath), new PdfWriter(outFilePath))
becomes this one:
new PdfDocument(new PdfReader(new FileInputStream(inFilePath)),
new PdfWriter(new FileOutputStream(outFilePath)))
You might also want to wrap the streams into BufferedInputStream/BufferedOutputStream.
Similarly, when dealing with PdfFontFactory, use methods that accept byte[] instead of String representing file path and so on.
If you're curious what is the Illegal Reflective Access is all about, please refer here: what is an illegal reflective access
This particular warning comes from this class:
https://github.com/itext/itext7/blob/develop/io/src/main/java/com/itextpdf/io/source/ByteBufferRandomAccessSource.java
From this particular method:
private static boolean clean(final java.nio.ByteBuffer buffer) {
if (buffer == null || !buffer.isDirect())
return false;
Boolean b = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
public Boolean run() {
Boolean success = Boolean.FALSE;
try {
// java 9
if (UNMAP_SUPPORTED)
CLEANER.freeBuffer(buffer.toString(), buffer);
// java 8 and lower
else {
Method getCleanerMethod = buffer.getClass().getMethod("cleaner", (Class<?>[]) null);
getCleanerMethod.setAccessible(true);
Object cleaner = getCleanerMethod.invoke(buffer, (Object[]) null);
Method clean = cleaner.getClass().getMethod("clean", (Class<?>[]) null);
clean.invoke(cleaner, (Object[]) null);
}
success = Boolean.TRUE;
} catch (Exception e) {
// This really is a show stopper on windows
Logger logger = LoggerFactory.getLogger(ByteBufferRandomAccessSource.class);
logger.debug(e.getMessage());
}
return success;
}
});
return b;
}
This line exactly:
getCleanerMethod.setAccessible(true);
As long as this warning does not prevent iText from working as expected, I think the best you can do is to submit an issue/PR to iText team and wait for the proper fix to be available.

What is .Net Socket.Handle equivalent for java

In java is there any functionality equivalent to below c# functionality.
Socket.Handle
https://msdn.microsoft.com/en-us/library/system.net.sockets.socket.handle(v=vs.110).aspx
I have searched on internet and also I checked the properties of java.net.Socket but I could not extract similar thing. Any information is appreciated.
Thank you so much.
If I understood correctly, you basically need socket.getImpl().getFileDescriptor().fd. None of these methods/fields are public, leaving reflection as your only option:
static int getHandle(Socket socket) throws ReflectiveOperationException {
Method getImpl = Socket.class.getDeclaredMethod("getImpl");
getImpl.setAccessible(true);
SocketImpl impl = (SocketImpl) getImpl.invoke(socket);
Method getFileDescriptor = SocketImpl.class.getDeclaredMethod("getFileDescriptor");
getFileDescriptor.setAccessible(true);
FileDescriptor fileDescriptor = (FileDescriptor) getFileDescriptor.invoke(impl);
Field fd = FileDescriptor.class.getDeclaredField("fd");
fd.setAccessible(true);
return (int) fd.get(fileDescriptor);
}
As of Java 9, this comes with a bunch of warnings:
WARNING: An illegal reflective access operation has occurred
...
WARNING: All illegal access operations will be denied in a future release
As a conclusion, (plain) Java is probably not the right tool for this requirement.

java mongo about org.bson.BsonSerializationException

Recently I found that Java-mongodb-driver offered some exceptions:
org.bson.BsonSerializationException: Detected unknown BSON type "\xce" for fieldname "����\�z". Are you using the latest driver version?
org.bson.BsonBinaryReader.readBsonType(BsonBinaryReader.java:95)
com.mongodb.connection.ProtocolHelper.getField(ProtocolHelper.java:87)
com.mongodb.connection.ProtocolHelper.isCommandOk(ProtocolHelper.java:82)
com.mongodb.connection.CommandProtocol.execute(CommandProtocol.java:113)
com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:168)
com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:289)
com.mongodb.connection.DefaultServerConnection.command(DefaultServerConnection.java:176)
com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:216)
com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:207)
com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:113)
com.mongodb.operation.FindOperation$1.call(FindOperation.java:516)
com.mongodb.operation.FindOperation$1.call(FindOperation.java:510)
com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:431)
com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:404)
com.mongodb.operation.FindOperation.execute(FindOperation.java:510)
com.mongodb.operation.FindOperation.execute(FindOperation.java:81)
com.mongodb.Mongo.execute(Mongo.java:836)
com.mongodb.Mongo$2.execute(Mongo.java:823)
com.mongodb.FindIterableImpl$FindOperationIterable.first(FindIterableImpl.java:216)
com.mongodb.FindIterableImpl.first(FindIterableImpl.java:156)
I want to know what circumstance can cause this problem, how to solve

disable strict mode in drools

I'm getting error like Error: unable to resolve method using strict-mode: ...
I've added system property drools.dialect.mvel.strict=false
I can see system property was applied to my app in jvisualvm
But I'm getting the same error with 'using strict-mode'.
How could I disable strict mode in drools?
This is how it can be done from Java:
KnowledgeBuilderConfiguration kbConfig =
KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
kbConfig.setProperty("drools.dialect.mvel.strict", "false");
KnowledgeBuilder kBuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder( kbConfig );
Although, setting the property should be OK. -- Maybe a look at the error might help to find a workaround?

Categories

Resources