Skip to content

Commit 99ce7f1

Browse files
authored
Merge pull request #9 from mojo2012/master
catch native code exceptions and forward to jvm
2 parents c1aa830 + 2c41ab1 commit 99ce7f1

File tree

17 files changed

+2475
-72
lines changed

17 files changed

+2475
-72
lines changed

Diff for: .classpath

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="java/src"/>
4+
<classpathentry kind="src" path="java/test"/>
5+
<classpathentry kind="src" path="samples/BringToFrontSample/src"/>
6+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
7+
<attributes>
8+
<attribute name="module" value="true"/>
9+
</attributes>
10+
</classpathentry>
11+
<classpathentry kind="lib" path="dist/jna-4.0.0.jar"/>
12+
<classpathentry kind="lib" path="dist/ObjCBridge.jar"/>
13+
<classpathentry kind="lib" path="java/lib/jna.jar"/>
14+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
15+
<classpathentry kind="output" path="bin"/>
16+
</classpath>

Diff for: .gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
/samples/BringToFrontSample/nbproject/private/
55
/samples/BringToFrontSample/build/
66
.DS_Store
7-
private
7+
private
8+
/bin/

Diff for: .project

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>Java-Objective-C-Bridge</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

Diff for: java/src/ca/weblite/objc/NSObject.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
* @author shannah
5656
*/
5757
public class NSObject extends Proxy implements PeerableRecipient {
58-
58+
private static final Logger LOG = Logger.getLogger("NSObject");
5959

6060

6161
/**
@@ -514,6 +514,7 @@ public void forwardInvocation(long linvocation) {
514514

515515
return;
516516
} catch (Exception ex){
517+
LOG.log(Level.SEVERE, String.format("Method invocation caused exception: %s", method));
517518
ex.printStackTrace(System.err);
518519
throw new RuntimeException(ex);
519520
}

Diff for: native/Info.plist

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>English</string>
7+
<key>CFBundleExecutable</key>
8+
<string>libjli.dylib</string>
9+
<key>CFBundleGetInfoString</key>
10+
<string>OpenJDK 11.0.2+9</string>
11+
<key>CFBundleIdentifier</key>
12+
<string>net.java.openjdk.11.0.2.jdk</string>
13+
<key>CFBundleInfoDictionaryVersion</key>
14+
<string>7.0</string>
15+
<key>CFBundleName</key>
16+
<string>OpenJDK 11.0.2</string>
17+
<key>CFBundlePackageType</key>
18+
<string>BNDL</string>
19+
<key>CFBundleShortVersionString</key>
20+
<string>1.0</string>
21+
<key>CFBundleSignature</key>
22+
<string>????</string>
23+
<key>CFBundleVersion</key>
24+
<string>11.0.2</string>
25+
<key>JavaVM</key>
26+
<dict>
27+
<key>JVMCapabilities</key>
28+
<array>
29+
<string>CommandLine</string>
30+
</array>
31+
<key>JVMMinimumFrameworkVersion</key>
32+
<string>13.2.9</string>
33+
<key>JVMMinimumSystemVersion</key>
34+
<string>10.6.0</string>
35+
<key>JVMPlatformVersion</key>
36+
<string>11.0</string>
37+
<key>JVMVendor</key>
38+
<string>Oracle Corporation</string>
39+
<key>JVMVersion</key>
40+
<string>11.0.2</string>
41+
</dict>
42+
</dict>
43+
</plist>

Diff for: native/libjcocoa.xcodeproj/project.pbxproj

+19-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
65152933163458E2002A41D8 /* WLJavaProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = 65152931163458E2002A41D8 /* WLJavaProxy.m */; };
2121
651529461634837A002A41D8 /* jnaexample_NativeClient_Setup.h in Headers */ = {isa = PBXBuildFile; fileRef = 651529441634837A002A41D8 /* jnaexample_NativeClient_Setup.h */; };
2222
651529471634837A002A41D8 /* jnaexample_NativeClient_Setup.m in Sources */ = {isa = PBXBuildFile; fileRef = 651529451634837A002A41D8 /* jnaexample_NativeClient_Setup.m */; };
23+
83CD42CB22A6CE3800F857EC /* JavaUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 83CD42CA22A6CE3800F857EC /* JavaUtil.m */; };
24+
83CD42D022A6CEA300F857EC /* jni.h in Headers */ = {isa = PBXBuildFile; fileRef = 83CD42CE22A6CEA300F857EC /* jni.h */; };
25+
83CD42D122A6CEA300F857EC /* jni_md.h in Headers */ = {isa = PBXBuildFile; fileRef = 83CD42CF22A6CEA300F857EC /* jni_md.h */; };
2326
/* End PBXBuildFile section */
2427

2528
/* Begin PBXContainerItemProxy section */
@@ -54,6 +57,11 @@
5457
651529451634837A002A41D8 /* jnaexample_NativeClient_Setup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = jnaexample_NativeClient_Setup.m; sourceTree = "<group>"; };
5558
65A0F1671639C1630036209C /* Window.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = Window.xib; sourceTree = "<group>"; };
5659
65A0F1691639C4640036209C /* Application.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = Application.xib; sourceTree = "<group>"; };
60+
83CD42C922A6CE1000F857EC /* JavaUtil.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JavaUtil.h; sourceTree = "<group>"; };
61+
83CD42CA22A6CE3800F857EC /* JavaUtil.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JavaUtil.m; sourceTree = "<group>"; };
62+
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>"; };
63+
83CD42CE22A6CEA300F857EC /* jni.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = jni.h; sourceTree = "<group>"; };
64+
83CD42CF22A6CEA300F857EC /* jni_md.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = jni_md.h; sourceTree = "<group>"; };
5765
/* End PBXFileReference section */
5866

5967
/* Begin PBXFrameworksBuildPhase section */
@@ -91,6 +99,7 @@
9199
651528F9163458B4002A41D8 = {
92100
isa = PBXGroup;
93101
children = (
102+
83CD42CC22A6CE8700F857EC /* Info.plist */,
94103
6515290D163458B4002A41D8 /* libjcocoa */,
95104
6515291F163458B4002A41D8 /* libjcocoaTests */,
96105
65152906163458B4002A41D8 /* Frameworks */,
@@ -131,11 +140,13 @@
131140
6515290D163458B4002A41D8 /* libjcocoa */ = {
132141
isa = PBXGroup;
133142
children = (
143+
6515290E163458B4002A41D8 /* Supporting Files */,
144+
83CD42C922A6CE1000F857EC /* JavaUtil.h */,
145+
83CD42CA22A6CE3800F857EC /* JavaUtil.m */,
134146
651529441634837A002A41D8 /* jnaexample_NativeClient_Setup.h */,
135147
651529451634837A002A41D8 /* jnaexample_NativeClient_Setup.m */,
136148
65152910163458B4002A41D8 /* libjcocoa.h */,
137149
65152911163458B4002A41D8 /* libjcocoa.m */,
138-
6515290E163458B4002A41D8 /* Supporting Files */,
139150
65152930163458E2002A41D8 /* WLJavaProxy.h */,
140151
65152931163458E2002A41D8 /* WLJavaProxy.m */,
141152
65A0F1671639C1630036209C /* Window.xib */,
@@ -147,6 +158,8 @@
147158
6515290E163458B4002A41D8 /* Supporting Files */ = {
148159
isa = PBXGroup;
149160
children = (
161+
83CD42CF22A6CEA300F857EC /* jni_md.h */,
162+
83CD42CE22A6CEA300F857EC /* jni.h */,
150163
6515290F163458B4002A41D8 /* libjcocoa-Prefix.pch */,
151164
);
152165
name = "Supporting Files";
@@ -155,9 +168,9 @@
155168
6515291F163458B4002A41D8 /* libjcocoaTests */ = {
156169
isa = PBXGroup;
157170
children = (
171+
65152920163458B4002A41D8 /* Supporting Files */,
158172
65152925163458B4002A41D8 /* libjcocoaTests.h */,
159173
65152926163458B4002A41D8 /* libjcocoaTests.m */,
160-
65152920163458B4002A41D8 /* Supporting Files */,
161174
);
162175
path = libjcocoaTests;
163176
sourceTree = "<group>";
@@ -178,6 +191,8 @@
178191
isa = PBXHeadersBuildPhase;
179192
buildActionMask = 2147483647;
180193
files = (
194+
83CD42D022A6CEA300F857EC /* jni.h in Headers */,
195+
83CD42D122A6CEA300F857EC /* jni_md.h in Headers */,
181196
65152932163458E2002A41D8 /* WLJavaProxy.h in Headers */,
182197
651529461634837A002A41D8 /* jnaexample_NativeClient_Setup.h in Headers */,
183198
);
@@ -236,6 +251,7 @@
236251
developmentRegion = English;
237252
hasScannedForEncodings = 0;
238253
knownRegions = (
254+
English,
239255
en,
240256
);
241257
mainGroup = 651528F9163458B4002A41D8;
@@ -283,6 +299,7 @@
283299
buildActionMask = 2147483647;
284300
files = (
285301
65152912163458B4002A41D8 /* libjcocoa.m in Sources */,
302+
83CD42CB22A6CE3800F857EC /* JavaUtil.m in Sources */,
286303
65152933163458E2002A41D8 /* WLJavaProxy.m in Sources */,
287304
651529471634837A002A41D8 /* jnaexample_NativeClient_Setup.m in Sources */,
288305
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1020"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "65152903163458B4002A41D8"
18+
BuildableName = "libjcocoa.dylib"
19+
BlueprintName = "libjcocoa"
20+
ReferencedContainer = "container:libjcocoa.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
</Testables>
32+
<AdditionalOptions>
33+
</AdditionalOptions>
34+
</TestAction>
35+
<LaunchAction
36+
buildConfiguration = "Debug"
37+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
38+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
39+
launchStyle = "0"
40+
useCustomWorkingDirectory = "NO"
41+
ignoresPersistentStateOnLaunch = "NO"
42+
debugDocumentVersioning = "YES"
43+
debugServiceExtension = "internal"
44+
allowLocationSimulation = "YES">
45+
<MacroExpansion>
46+
<BuildableReference
47+
BuildableIdentifier = "primary"
48+
BlueprintIdentifier = "65152903163458B4002A41D8"
49+
BuildableName = "libjcocoa.dylib"
50+
BlueprintName = "libjcocoa"
51+
ReferencedContainer = "container:libjcocoa.xcodeproj">
52+
</BuildableReference>
53+
</MacroExpansion>
54+
<AdditionalOptions>
55+
</AdditionalOptions>
56+
</LaunchAction>
57+
<ProfileAction
58+
buildConfiguration = "Release"
59+
shouldUseLaunchSchemeArgsEnv = "YES"
60+
savedToolIdentifier = ""
61+
useCustomWorkingDirectory = "NO"
62+
debugDocumentVersioning = "YES">
63+
<MacroExpansion>
64+
<BuildableReference
65+
BuildableIdentifier = "primary"
66+
BlueprintIdentifier = "65152903163458B4002A41D8"
67+
BuildableName = "libjcocoa.dylib"
68+
BlueprintName = "libjcocoa"
69+
ReferencedContainer = "container:libjcocoa.xcodeproj">
70+
</BuildableReference>
71+
</MacroExpansion>
72+
</ProfileAction>
73+
<AnalyzeAction
74+
buildConfiguration = "Debug">
75+
</AnalyzeAction>
76+
<ArchiveAction
77+
buildConfiguration = "Release"
78+
revealArchiveInOrganizer = "YES">
79+
</ArchiveAction>
80+
</Scheme>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>SchemeUserState</key>
6+
<dict>
7+
<key>libjcocoa.xcscheme_^#shared#^_</key>
8+
<dict>
9+
<key>orderHint</key>
10+
<integer>0</integer>
11+
</dict>
12+
<key>libjcocoaTests.xcscheme_^#shared#^_</key>
13+
<dict>
14+
<key>orderHint</key>
15+
<integer>1</integer>
16+
</dict>
17+
</dict>
18+
</dict>
19+
</plist>

Diff for: native/libjcocoa/JavaUtil.h

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// JavaUtil.h
3+
// libjcocoa
4+
//
5+
// Created by Matthias Fuchs on 04.06.19.
6+
// Copyright © 2019 Web Lite Solutions. All rights reserved.
7+
//
8+
9+
#ifndef JavaUtil_h
10+
#define JavaUtil_h
11+
#import <jni.h>
12+
13+
@interface JavaUtil : NSObject
14+
15+
+(void) throwJavaException:(JNIEnv *)env withMessage: (const char *)msg;
16+
17+
@end
18+
19+
#endif /* JavaUtil_h */

Diff for: native/libjcocoa/JavaUtil.m

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// JavaUtil.m
3+
// libjcocoa
4+
//
5+
// Created by Matthias Fuchs on 04.06.19.
6+
// Copyright © 2019 Web Lite Solutions. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "JavaUtil.h"
11+
12+
@implementation JavaUtil
13+
14+
+(void) throwJavaException:(JNIEnv *)env withMessage: (const char *)msg
15+
{
16+
// You can put your own exception here
17+
jclass c = (*env)->FindClass(env, "java/lang/RuntimeException");
18+
19+
(*env)->ThrowNew(env, c, msg);
20+
}
21+
22+
@end

Diff for: native/libjcocoa/WLJavaProxy.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#import <Foundation/Foundation.h>
1010
#import <jni.h>
1111

12-
@interface WLJavaProxy : NSProxy {
12+
@interface WLJavaProxy : NSObject {
1313
jobject peer;
1414
jclass peerClass;
1515
jmethodID jMethodSignatureForSelector;

0 commit comments

Comments
 (0)