@@ -164,6 +164,10 @@ public struct JavaCoderConfig {
164
164
var locals = [ jobject] ( )
165
165
let javaString = ( $0 as! URL ) . absoluteString. localJavaObject ( & locals)
166
166
let args = [ jvalue ( l: javaString) ]
167
+ JNI . SaveFatalErrorMessage ( " UriConstructor " )
168
+ defer {
169
+ JNI . RemoveFatalErrorMessage ( )
170
+ }
167
171
return JNI . check ( JNI . CallStaticObjectMethod ( UriClass, methodID: UriConstructor!, args: args) !, & locals)
168
172
} , decodableClosure: {
169
173
let pathString = JNI . api. CallObjectMethodA ( JNI . env, $0, ObjectToStringMethod, nil )
@@ -172,10 +176,22 @@ public struct JavaCoderConfig {
172
176
173
177
RegisterType ( type: Data . self, javaClassname: ByteBufferClassname, encodableClosure: {
174
178
let valueData = $0 as! Data
175
- let byteArray = JNI . api. NewByteArray ( JNI . env, valueData. count) !
179
+ let byteArray = JNI . api. NewByteArray ( JNI . env, valueData. count)
180
+ if let throwable = JNI . ExceptionCheck ( ) {
181
+ throw EncodingError . invalidValue ( $0, EncodingError . Context ( codingPath: [ ] ,
182
+ debugDescription: " Can't create NewByteArray \( valueData. count) " ) )
183
+ }
176
184
valueData. withUnsafeBytes ( { ( pointer: UnsafePointer < Int8 > ) -> Void in
177
185
JNI . api. SetByteArrayRegion ( JNI . env, byteArray, 0 , valueData. count, pointer)
178
186
} )
187
+ if let throwable = JNI . ExceptionCheck ( ) {
188
+ throw EncodingError . invalidValue ( $0, EncodingError . Context ( codingPath: [ ] ,
189
+ debugDescription: " SetByteArrayRegion failed \( valueData. count) " ) )
190
+ }
191
+ JNI . SaveFatalErrorMessage ( " java/nio/ByteBuffer wrap " )
192
+ defer {
193
+ JNI . RemoveFatalErrorMessage ( )
194
+ }
179
195
return JNI . CallStaticObjectMethod ( ByteBufferClass, methodID: ByteBufferWrap, args: [ jvalue ( l: byteArray) ] ) !
180
196
} , decodableClosure: {
181
197
let byteArray = JNI . CallObjectMethod ( $0, methodID: ByteBufferArray)
@@ -186,7 +202,7 @@ public struct JavaCoderConfig {
186
202
defer {
187
203
JNI . api. ReleaseByteArrayElements ( JNI . env, byteArray, pointer, 0 )
188
204
}
189
- return Data . init ( bytes: pointer, count: length)
205
+ return Data ( bytes: pointer, count: length)
190
206
} )
191
207
}
192
208
0 commit comments