Skip to content

catch native code exceptions and forward to jvm #9

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 5 commits into from
Jun 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="java/src"/>
<classpathentry kind="src" path="java/test"/>
<classpathentry kind="src" path="samples/BringToFrontSample/src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="dist/jna-4.0.0.jar"/>
<classpathentry kind="lib" path="dist/ObjCBridge.jar"/>
<classpathentry kind="lib" path="java/lib/jna.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="bin"/>
</classpath>
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
/samples/BringToFrontSample/nbproject/private/
/samples/BringToFrontSample/build/
.DS_Store
private
private
/bin/
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Java-Objective-C-Bridge</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
3 changes: 2 additions & 1 deletion java/src/ca/weblite/objc/NSObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
* @author shannah
*/
public class NSObject extends Proxy implements PeerableRecipient {

private static final Logger LOG = Logger.getLogger("NSObject");


/**
Expand Down Expand Up @@ -514,6 +514,7 @@ public void forwardInvocation(long linvocation) {

return;
} catch (Exception ex){
LOG.log(Level.SEVERE, String.format("Method invocation caused exception: %s", method));
ex.printStackTrace(System.err);
throw new RuntimeException(ex);
}
Expand Down
43 changes: 43 additions & 0 deletions native/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>libjli.dylib</string>
<key>CFBundleGetInfoString</key>
<string>OpenJDK 11.0.2+9</string>
<key>CFBundleIdentifier</key>
<string>net.java.openjdk.11.0.2.jdk</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>7.0</string>
<key>CFBundleName</key>
<string>OpenJDK 11.0.2</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>11.0.2</string>
<key>JavaVM</key>
<dict>
<key>JVMCapabilities</key>
<array>
<string>CommandLine</string>
</array>
<key>JVMMinimumFrameworkVersion</key>
<string>13.2.9</string>
<key>JVMMinimumSystemVersion</key>
<string>10.6.0</string>
<key>JVMPlatformVersion</key>
<string>11.0</string>
<key>JVMVendor</key>
<string>Oracle Corporation</string>
<key>JVMVersion</key>
<string>11.0.2</string>
</dict>
</dict>
</plist>
21 changes: 19 additions & 2 deletions native/libjcocoa.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
65152933163458E2002A41D8 /* WLJavaProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = 65152931163458E2002A41D8 /* WLJavaProxy.m */; };
651529461634837A002A41D8 /* jnaexample_NativeClient_Setup.h in Headers */ = {isa = PBXBuildFile; fileRef = 651529441634837A002A41D8 /* jnaexample_NativeClient_Setup.h */; };
651529471634837A002A41D8 /* jnaexample_NativeClient_Setup.m in Sources */ = {isa = PBXBuildFile; fileRef = 651529451634837A002A41D8 /* jnaexample_NativeClient_Setup.m */; };
83CD42CB22A6CE3800F857EC /* JavaUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 83CD42CA22A6CE3800F857EC /* JavaUtil.m */; };
83CD42D022A6CEA300F857EC /* jni.h in Headers */ = {isa = PBXBuildFile; fileRef = 83CD42CE22A6CEA300F857EC /* jni.h */; };
83CD42D122A6CEA300F857EC /* jni_md.h in Headers */ = {isa = PBXBuildFile; fileRef = 83CD42CF22A6CEA300F857EC /* jni_md.h */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -54,6 +57,11 @@
651529451634837A002A41D8 /* jnaexample_NativeClient_Setup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = jnaexample_NativeClient_Setup.m; sourceTree = "<group>"; };
65A0F1671639C1630036209C /* Window.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = Window.xib; sourceTree = "<group>"; };
65A0F1691639C4640036209C /* Application.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = Application.xib; sourceTree = "<group>"; };
83CD42C922A6CE1000F857EC /* JavaUtil.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JavaUtil.h; sourceTree = "<group>"; };
83CD42CA22A6CE3800F857EC /* JavaUtil.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JavaUtil.m; sourceTree = "<group>"; };
83CD42CC22A6CE8700F857EC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; name = Info.plist; path = "../../../../../../Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Info.plist"; sourceTree = "<group>"; };
83CD42CE22A6CEA300F857EC /* jni.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = jni.h; sourceTree = "<group>"; };
83CD42CF22A6CEA300F857EC /* jni_md.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = jni_md.h; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -91,6 +99,7 @@
651528F9163458B4002A41D8 = {
isa = PBXGroup;
children = (
83CD42CC22A6CE8700F857EC /* Info.plist */,
6515290D163458B4002A41D8 /* libjcocoa */,
6515291F163458B4002A41D8 /* libjcocoaTests */,
65152906163458B4002A41D8 /* Frameworks */,
Expand Down Expand Up @@ -131,11 +140,13 @@
6515290D163458B4002A41D8 /* libjcocoa */ = {
isa = PBXGroup;
children = (
6515290E163458B4002A41D8 /* Supporting Files */,
83CD42C922A6CE1000F857EC /* JavaUtil.h */,
83CD42CA22A6CE3800F857EC /* JavaUtil.m */,
651529441634837A002A41D8 /* jnaexample_NativeClient_Setup.h */,
651529451634837A002A41D8 /* jnaexample_NativeClient_Setup.m */,
65152910163458B4002A41D8 /* libjcocoa.h */,
65152911163458B4002A41D8 /* libjcocoa.m */,
6515290E163458B4002A41D8 /* Supporting Files */,
65152930163458E2002A41D8 /* WLJavaProxy.h */,
65152931163458E2002A41D8 /* WLJavaProxy.m */,
65A0F1671639C1630036209C /* Window.xib */,
Expand All @@ -147,6 +158,8 @@
6515290E163458B4002A41D8 /* Supporting Files */ = {
isa = PBXGroup;
children = (
83CD42CF22A6CEA300F857EC /* jni_md.h */,
83CD42CE22A6CEA300F857EC /* jni.h */,
6515290F163458B4002A41D8 /* libjcocoa-Prefix.pch */,
);
name = "Supporting Files";
Expand All @@ -155,9 +168,9 @@
6515291F163458B4002A41D8 /* libjcocoaTests */ = {
isa = PBXGroup;
children = (
65152920163458B4002A41D8 /* Supporting Files */,
65152925163458B4002A41D8 /* libjcocoaTests.h */,
65152926163458B4002A41D8 /* libjcocoaTests.m */,
65152920163458B4002A41D8 /* Supporting Files */,
);
path = libjcocoaTests;
sourceTree = "<group>";
Expand All @@ -178,6 +191,8 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
83CD42D022A6CEA300F857EC /* jni.h in Headers */,
83CD42D122A6CEA300F857EC /* jni_md.h in Headers */,
65152932163458E2002A41D8 /* WLJavaProxy.h in Headers */,
651529461634837A002A41D8 /* jnaexample_NativeClient_Setup.h in Headers */,
);
Expand Down Expand Up @@ -236,6 +251,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
);
mainGroup = 651528F9163458B4002A41D8;
Expand Down Expand Up @@ -283,6 +299,7 @@
buildActionMask = 2147483647;
files = (
65152912163458B4002A41D8 /* libjcocoa.m in Sources */,
83CD42CB22A6CE3800F857EC /* JavaUtil.m in Sources */,
65152933163458E2002A41D8 /* WLJavaProxy.m in Sources */,
651529471634837A002A41D8 /* jnaexample_NativeClient_Setup.m in Sources */,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "65152903163458B4002A41D8"
BuildableName = "libjcocoa.dylib"
BlueprintName = "libjcocoa"
ReferencedContainer = "container:libjcocoa.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "65152903163458B4002A41D8"
BuildableName = "libjcocoa.dylib"
BlueprintName = "libjcocoa"
ReferencedContainer = "container:libjcocoa.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "65152903163458B4002A41D8"
BuildableName = "libjcocoa.dylib"
BlueprintName = "libjcocoa"
ReferencedContainer = "container:libjcocoa.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>libjcocoa.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
<key>libjcocoaTests.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
</dict>
</dict>
</plist>
19 changes: 19 additions & 0 deletions native/libjcocoa/JavaUtil.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// JavaUtil.h
// libjcocoa
//
// Created by Matthias Fuchs on 04.06.19.
// Copyright © 2019 Web Lite Solutions. All rights reserved.
//

#ifndef JavaUtil_h
#define JavaUtil_h
#import <jni.h>

@interface JavaUtil : NSObject

+(void) throwJavaException:(JNIEnv *)env withMessage: (const char *)msg;

@end

#endif /* JavaUtil_h */
22 changes: 22 additions & 0 deletions native/libjcocoa/JavaUtil.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// JavaUtil.m
// libjcocoa
//
// Created by Matthias Fuchs on 04.06.19.
// Copyright © 2019 Web Lite Solutions. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "JavaUtil.h"

@implementation JavaUtil

+(void) throwJavaException:(JNIEnv *)env withMessage: (const char *)msg
{
// You can put your own exception here
jclass c = (*env)->FindClass(env, "java/lang/RuntimeException");

(*env)->ThrowNew(env, c, msg);
}

@end
2 changes: 1 addition & 1 deletion native/libjcocoa/WLJavaProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import <Foundation/Foundation.h>
#import <jni.h>

@interface WLJavaProxy : NSProxy {
@interface WLJavaProxy : NSObject {
jobject peer;
jclass peerClass;
jmethodID jMethodSignatureForSelector;
Expand Down
Loading