Fix and cleanup class name / path#56
Conversation
📝 Kodiai Draft Review Summary
What ChangedThis PR refactors the libandroidjni codebase to clarify the distinction between "class names" (the/class/name) and "fully qualified class name paths" (the.class.name), and introduces a configurable base class name mechanism to fix issues when the library is used as a dependency. Reviewed: core logic Strengths
ObservationsImpact[CRITICAL] src/JNIBase.cpp (27-29): Missing static member initialization for m_baseClassName [MAJOR] src/MediaDrmOnEventListener.cpp (33): Type mismatch - passing class name to loadClass() instead of class path [MAJOR] src/InputManager.cpp (39-40): Manual conversion duplicates ClassNameToPath functionality Preference[MINOR] src/ClassLoader.h (33): Documentation inconsistency - parameter description doesn't match signature Suggestions
Verdict🔴 Address before merging -- (3) blocking issue(s) found (CRITICAL/MAJOR) Review Details
|
|
@kodiai propose a diff patch fix for your suggestion about to add assertion to verify that |
kodiai responseHere's a diff patch that adds an assertion to verify diff --git a/src/JNIBase.h b/src/JNIBase.h
index 1234567..abcdefg 100644
--- a/src/JNIBase.h
+++ b/src/JNIBase.h
@@ -21,6 +21,7 @@
#include "jutils.hpp"
+#include <cassert>
#include <list>
class CJNIBase
diff --git a/src/JNIBase.cpp b/src/JNIBase.cpp
index 1234567..abcdefg 100644
--- a/src/JNIBase.cpp
+++ b/src/JNIBase.cpp
@@ -30,8 +30,18 @@ int CJNIBase::RESULT_CANCELED = 0;
CJNIBase::CJNIBase(std::string className)
{
- // If starts with / add the base class name prefix (e.g. org/xbmc/kodi)
+ // If starts with "/" add the base class name prefix (e.g. org/xbmc/kodi)
if (!className.empty() && className.front() == '/')
+ {
+ // Verify that SetBaseClassName() has been called before instantiating
+ // any class using the "/" prefix pattern to avoid initialization order issues
+ assert(!m_baseClassName.empty() &&
+ "SetBaseClassName() must be called before instantiating classes with '/' prefix. "
+ "Add-ons using libandroidjni as a dependency should call CJNIBase::SetBaseClassName() "
+ "with their package name (e.g. 'org/xbmc/kodi') during initialization.");
+
className = GetBaseClassName() + className;
+ }
m_className = className;
}How it works: (1) The assertion is placed in the (2) It verifies that (3) The assertion message clearly explains:
(4) This catches the initialization order issue early at development/debug time rather than causing runtime failures later when class loading fails. Example failure scenario: If an add-on creates a |
bb3e662 to
36d73f6
Compare
|
@kodiai i updated PR, please give a draft review |
36d73f6 to
0c6a5a2
Compare
|
The |
|
yes internally CJNIBase was doing the thing to "convert" the class name passed, but this was not clear and make only messy code for example |
|
I find it more flexible and robust to allow initialization using both ways of representing the class. Agreed, One more thing: why aren't you using |
I don't fully agree, yes its more flexible, but prone to making easy mistakes, so better the explicit way
where you mean? about this on CJNIBase? from addon side you can get it by calling interface |
d5681bd to
84e9824
Compare
|
Doesn't this also need to be adjusted? |
thanks for point it out, for consistency i will change it to "Kodi" as already used in xbmc |
b71fff8 to
123aa2d
Compare
|
@kodiai updated PR, please do last review |
kodiai responseDecision: NOT APPROVED Issues:
|
123aa2d to
ec8daa4
Compare
|
@kodiai fixed your critical issue, please finish review |
An issue has been raised when libandroidjni was used as a dependency of InputStream Adaptive
xbmc/inputstream.adaptive#1997
where the
CJNIMediaDrmOnEventListenerhas the class name hardcoded with the "base" class nameor in other hand the kodi package name
libandroidjni/src/MediaDrmOnEventListener.cpp
Line 28 in 59b6850
while investigating for a fix i noticed also some confusion between class names / paths uses i mean "the/class/name" vs "the.class.name", where in some cases both are mixed
"the/class/name" --> can be defined as "class name"
"the.class.name" --> can be defined as "fully qualified class name" aka path
Based on these definitions i cleaned up the code by adding more clear methods descriptions to avoid future mixed usages
the
CJNIBasehas the newSetBaseClassNamethat can be used by add-ons to set the "base" class name provided by InputStream android interface (example on xbmc/inputstream.adaptive#2007)