Skip to content

Commit 1c74f7c

Browse files
committed
glue: add error checks after invoking JNIEnv::NewStringUTF()
1 parent ea2c00d commit 1c74f7c

File tree

8 files changed

+30
-6
lines changed

8 files changed

+30
-6
lines changed

src/main/native/glue/co/ConvexHullBuilder.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2024-2025 Stephen Gold
2+
Copyright (c) 2024-2026 Stephen Gold
33
44
Permission is hereby granted, free of charge, to any person obtaining a copy
55
of this software and associated documentation files (the "Software"), to deal
@@ -169,6 +169,8 @@ JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_ConvexHullBuilder_ini
169169
pMessage = "";
170170
}
171171
jstring message = pEnv->NewStringUTF(pMessage);
172+
JPH_ASSERT(NULL != message);
173+
EXCEPTION_CHECK(pEnv)
172174
pEnv->SetObjectArrayElement(storeMessage, (jsize)0, message);
173175
return (jint) result;
174176
}

src/main/native/glue/d/Decomposer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2025 Stephen Gold
2+
Copyright (c) 2025-2026 Stephen Gold
33
44
Permission is hereby granted, free of charge, to any person obtaining a copy
55
of this software and associated documentation files (the "Software"), to deal
@@ -105,9 +105,11 @@ class Decomposer : public IVHACD::IUserCallback, public IVHACD::IUserLogger {
105105
jfloat arg3 = 100.0;
106106

107107
jstring arg4 = pAttachEnv->NewStringUTF(stageName);
108+
JPH_ASSERT(NULL != arg4);
108109
EXCEPTION_CHECK(pAttachEnv)
109110

110111
jstring arg5 = pAttachEnv->NewStringUTF(operationName);
112+
JPH_ASSERT(NULL != arg5);
111113
EXCEPTION_CHECK(pAttachEnv)
112114

113115
pAttachEnv->CallVoidMethod(mJavaObject, mUpdateMethodId,

src/main/native/glue/glue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ extern std::atomic<JPH::uint32> gDeleteCount;
186186
const String& message = pResult->GetError(); \
187187
const char* const str = message.c_str(); \
188188
const jstring result = pEnv->NewStringUTF(str); \
189+
JPH_ASSERT(NULL != result); \
190+
EXCEPTION_CHECK(pEnv) \
189191
return result; \
190192
} \
191193
JNIEXPORT jboolean JNICALL hasErrorName(JNIEnv *, jobject, jlong resultVa) { \

src/main/native/glue/j/Joint.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2024-2025 Stephen Gold
2+
Copyright (c) 2024-2026 Stephen Gold
33
44
Permission is hereby granted, free of charge, to any person obtaining a copy
55
of this software and associated documentation files (the "Software"), to deal
@@ -58,6 +58,8 @@ JNIEXPORT jstring JNICALL Java_com_github_stephengold_joltjni_Joint_getName
5858
const String name = pJoint->mName;
5959
const char * const pName = name.c_str();
6060
const jstring result = pEnv->NewStringUTF(pName);
61+
JPH_ASSERT(NULL != result);
62+
EXCEPTION_CHECK(pEnv)
6163
return result;
6264
}
6365

@@ -86,5 +88,7 @@ JNIEXPORT jstring JNICALL Java_com_github_stephengold_joltjni_Joint_getParentNam
8688
const String name = pJoint->mParentName;
8789
const char * const pName = name.c_str();
8890
const jstring result = pEnv->NewStringUTF(pName);
91+
JPH_ASSERT(NULL != result);
92+
EXCEPTION_CHECK(pEnv)
8993
return result;
9094
}

src/main/native/glue/j/Jolt.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ JNIEXPORT jstring JNICALL Java_com_github_stephengold_joltjni_Jolt_buildType
9797
#else
9898
result = pEnv->NewStringUTF("Release");
9999
#endif
100+
JPH_ASSERT(NULL != result);
101+
EXCEPTION_CHECK(pEnv)
100102
return result;
101103
}
102104

@@ -203,6 +205,8 @@ JNIEXPORT jstring JNICALL Java_com_github_stephengold_joltjni_Jolt_getConfigurat
203205
(JNIEnv *pEnv, jclass) {
204206
const char * const pString = GetConfigurationString();
205207
const jstring result = pEnv->NewStringUTF(pString);
208+
JPH_ASSERT(NULL != result);
209+
EXCEPTION_CHECK(pEnv)
206210
return result;
207211
}
208212

@@ -554,6 +558,7 @@ static void JavaTrace(const char *inFormat, ...) {
554558
// Create a Java string:
555559
jstring javaString = pAttachEnv->NewStringUTF(buffer);
556560
JPH_ASSERT(javaString != NULL);
561+
EXCEPTION_CHECK(pAttachEnv)
557562
// Print to the configured PrintStream:
558563
pAttachEnv->CallVoidMethod(gTraceStream, gPrintMethodId, javaString);
559564
EXCEPTION_CHECK(pAttachEnv)
@@ -871,6 +876,8 @@ JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_Jolt_unregisterTypes
871876
JNIEXPORT jstring JNICALL Java_com_github_stephengold_joltjni_Jolt_versionString
872877
(JNIEnv *pEnv, jclass) {
873878
const jstring result = pEnv->NewStringUTF(STRING(JOLT_JNI_VERSION_STRING));
879+
JPH_ASSERT(NULL != result);
880+
EXCEPTION_CHECK(pEnv)
874881
return result;
875882
}
876883

src/main/native/glue/ph/PhysicsMaterial.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2024-2025 Stephen Gold
2+
Copyright (c) 2024-2026 Stephen Gold
33
44
Permission is hereby granted, free of charge, to any person obtaining a copy
55
of this software and associated documentation files (the "Software"), to deal
@@ -64,6 +64,8 @@ JNIEXPORT jstring JNICALL Java_com_github_stephengold_joltjni_PhysicsMaterial_ge
6464
= reinterpret_cast<PhysicsMaterial *> (materialVa);
6565
const char * const pName = pMaterial->GetDebugName();
6666
const jstring result = pEnv->NewStringUTF(pName);
67+
JPH_ASSERT(NULL != result);
68+
EXCEPTION_CHECK(pEnv)
6769
return result;
6870
}
6971

src/main/native/glue/r/Rtti.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2025 Stephen Gold
2+
Copyright (c) 2025-2026 Stephen Gold
33
44
Permission is hereby granted, free of charge, to any person obtaining a copy
55
of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +26,7 @@ SOFTWARE.
2626
#include "Jolt/Jolt.h"
2727
#include "Jolt/Core/RTTI.h"
2828
#include "auto/com_github_stephengold_joltjni_Rtti.h"
29+
#include "glue/glue.h"
2930

3031
using namespace JPH;
3132

@@ -40,5 +41,7 @@ JNIEXPORT jstring JNICALL Java_com_github_stephengold_joltjni_Rtti_getName
4041
const String& message = pRtti->GetName();
4142
const char* const str = message.c_str();
4243
const jstring result = pEnv->NewStringUTF(str);
44+
JPH_ASSERT(NULL != result);
45+
EXCEPTION_CHECK(pEnv)
4346
return result;
4447
}

src/main/native/glue/st/StateRecorder.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2024-2025 Stephen Gold
2+
Copyright (c) 2024-2026 Stephen Gold
33
44
Permission is hereby granted, free of charge, to any person obtaining a copy
55
of this software and associated documentation files (the "Software"), to deal
@@ -154,6 +154,8 @@ JNIEXPORT jstring JNICALL Java_com_github_stephengold_joltjni_StateRecorder_read
154154
pRecorder->Read(cppString);
155155
const char * const pResult = cppString.c_str();
156156
const jstring result = pEnv->NewStringUTF(pResult);
157+
JPH_ASSERT(NULL != result);
158+
EXCEPTION_CHECK(pEnv)
157159
return result;
158160
}
159161

0 commit comments

Comments
 (0)