diff --color -ruN ./jpype/native/common/jp_context.cpp ./jpype.mod/native/common/jp_context.cpp
--- ./jpype/native/common/jp_context.cpp 2025-01-26 10:56:08.327270802 +0800
+++ ./jpype.mod/native/common/jp_context.cpp 2025-01-26 09:56:52.649778241 +0800
@@ -404,7 +404,7 @@
void JPContext::attachCurrentThread()
{
JNIEnv* env;
- jint res = m_JavaVM->functions->AttachCurrentThread(m_JavaVM, (void**) &env, nullptr);
+ jint res = m_JavaVM->functions->AttachCurrentThread(m_JavaVM, &env, nullptr);
if (res != JNI_OK)
JP_RAISE(PyExc_RuntimeError, "Unable to attach to thread");
}
@@ -412,7 +412,7 @@
void JPContext::attachCurrentThreadAsDaemon()
{
JNIEnv* env;
- jint res = m_JavaVM->functions->AttachCurrentThreadAsDaemon(m_JavaVM, (void**) &env, nullptr);
+ jint res = m_JavaVM->functions->AttachCurrentThreadAsDaemon(m_JavaVM, &env, nullptr);
if (res != JNI_OK)
JP_RAISE(PyExc_RuntimeError, "Unable to attach to thread as daemon");
}
@@ -444,7 +444,7 @@
{
// We will attach as daemon so that the newly attached thread does
// not deadlock the shutdown. The user can convert later if they want.
- res = m_JavaVM->AttachCurrentThreadAsDaemon((void**) &env, nullptr);
+ res = m_JavaVM->AttachCurrentThreadAsDaemon(&env, nullptr);
if (res != JNI_OK)
JP_RAISE(PyExc_RuntimeError, "Unable to attach to local thread");
}
diff --color -ruN ./jpype/native/java/org/jpype/JPypeClassLoader.java ./jpype.mod/native/java/org/jpype/JPypeClassLoader.java
--- ./jpype/native/java/org/jpype/JPypeClassLoader.java 2025-01-26 10:56:08.330604095 +0800
+++ ./jpype.mod/native/java/org/jpype/JPypeClassLoader.java 2025-01-26 10:50:46.037882437 +0800
@@ -184,32 +184,40 @@
@Override
public Class findClass(String name) throws ClassNotFoundException, ClassFormatError
{
- String aname = name.replace('.', '/') + ".class";
- URL url = this.getResource(aname);
- if (url == null)
- throw new ClassNotFoundException(name);
+ if (org.python.AndroidPlatform.isAndroid()) {
+ try {
+ // 尝试加载安卓系统特有的类
+ return Class.forName(name);
+ } catch (ClassNotFoundException e) {
+ throw new ClassNotFoundException(name);
+ }
- try
+ }
+ else
{
- URLConnection connection = url.openConnection();
- try (InputStream is = connection.getInputStream())
- {
- ByteArrayOutputStream buffer = new ByteArrayOutputStream();
- int bytes;
- byte[] d = new byte[1024];
- while ((bytes = is.read(d, 0, d.length)) != -1)
- {
- buffer.write(d, 0, bytes);
- }
+ String aname = name.replace('.', '/') + ".class";
+ URL url = this.getResource(aname);
+ if (url == null)
+ throw new ClassNotFoundException(name);
- buffer.flush();
- byte[] data = buffer.toByteArray();
- return defineClass(null, data, 0, data.length);
+ try {
+ URLConnection connection = url.openConnection();
+ try (InputStream is = connection.getInputStream()) {
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ int bytes;
+ byte[] d = new byte[1024];
+ while ((bytes = is.read(d, 0, d.length)) != -1) {
+ buffer.write(d, 0, bytes);
+ }
+
+ buffer.flush();
+ byte[] data = buffer.toByteArray();
+ return defineClass(null, data, 0, data.length);
+ }
+ } catch (IOException ex) {
}
- } catch (IOException ex)
- {
+ throw new ClassNotFoundException(name);
}
- throw new ClassNotFoundException(name);
}
@Override
diff --color -ruN ./jpype/native/java/org/jpype/JPypeContext.java ./jpype.mod/native/java/org/jpype/JPypeContext.java
--- ./jpype/native/java/org/jpype/JPypeContext.java 2025-01-26 10:56:08.330604095 +0800
+++ ./jpype.mod/native/java/org/jpype/JPypeContext.java 2025-01-26 11:17:57.416356259 +0800
@@ -650,7 +650,9 @@
private static long getHeapMemory()
{
- java.lang.management.MemoryMXBean memoryBean = java.lang.management.ManagementFactory.getMemoryMXBean();
- return memoryBean.getHeapMemoryUsage().getUsed();
+ //java.lang.management.MemoryMXBean memoryBean = java.lang.management.ManagementFactory.getMemoryMXBean();
+ //return memoryBean.getHeapMemoryUsage().getUsed();
+ Runtime runtime = Runtime.getRuntime();
+ return runtime.totalMemory() - runtime.freeMemory();
}
}
diff --color -ruN ./jpype/native/java/org/jpype/JPypeUtilities.java ./jpype.mod/native/java/org/jpype/JPypeUtilities.java
--- ./jpype/native/java/org/jpype/JPypeUtilities.java 2025-01-26 10:56:08.330604095 +0800
+++ ./jpype.mod/native/java/org/jpype/JPypeUtilities.java 2025-01-26 09:58:11.705731379 +0800
@@ -1,7 +1,7 @@
package org.jpype;
import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandleProxies;
+//import java.lang.invoke.MethodHandleProxies;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
@@ -26,6 +26,7 @@
static
{
Predicate<Class> result = null;
+ /*
try
{
Method m = Class.class.getMethod("isSealed");
@@ -40,6 +41,8 @@
// if isSealed doesn't exist then neither do sealed classes
result = c -> false;
}
+ */
+ result = c -> false;
isSealed = result;
}
Environment:
Issue Description:
The Android application crashes during JVM-Python interoperation through modified JPype bindings, showing a fatal
JPypeExceptionoriginating from native code. Key symptoms include:Critical Crash:
Patch info: