GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — BoxStore: verify that store is still open before using handle in nati… · zhoupan/objectbox-java@29e751b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • objectbox-java/src/main/java/io/objectbox
    • BoxStore.java
  • tests/objectbox-java-test/src/test/java/io/objectbox/exception
    • ExceptionTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎objectbox-java/src/main/java/io/objectbox/BoxStore.java‎

Copy file name to clipboardExpand all lines: objectbox-java/src/main/java/io/objectbox/BoxStore.java
+12-1Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2020 ObjectBox Ltd. All rights reserved.
2+
* Copyright 2017-2021 ObjectBox Ltd. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -542,6 +542,7 @@ public boolean isClosed() {
542542
* If true the schema is not updated and write transactions are not possible.
543543
*/
544544
public boolean isReadOnly() {
545+
checkOpen();
545546
return nativeIsReadOnly(handle);
546547
}
547548

@@ -578,6 +579,7 @@ public void close() {
578579
}
579580
if (handle != 0) { // failed before native handle was created?
580581
nativeDelete(handle);
582+
// TODO set handle to 0 and check in native methods
581583
}
582584

583585
// When running the full unit test suite, we had 100+ threads before, hope this helps:
@@ -721,6 +723,7 @@ public static boolean deleteAllFiles(@Nullable File baseDirectoryOrNull, @Nullab
721723
* </ul>
722724
*/
723725
public void removeAllObjects() {
726+
checkOpen();
724727
nativeDropAllData(handle);
725728
}
726729

@@ -1004,6 +1007,7 @@ public <R> void callInTxAsync(final Callable<R> callable, @Nullable final TxCall
10041007
* @return String that is typically logged by the application.
10051008
*/
10061009
public String diagnose() {
1010+
checkOpen();
10071011
return nativeDiagnose(handle);
10081012
}
10091013

@@ -1022,6 +1026,7 @@ public long validate(long pageLimit, boolean checkLeafLevel) {
10221026
if (pageLimit < 0) {
10231027
throw new IllegalArgumentException("pageLimit must be zero or positive");
10241028
}
1029+
checkOpen();
10251030
return nativeValidate(handle, pageLimit, checkLeafLevel);
10261031
}
10271032

@@ -1086,6 +1091,7 @@ public String startObjectBrowser() {
10861091
@Nullable
10871092
public String startObjectBrowser(int port) {
10881093
verifyObjectBrowserNotRunning();
1094+
checkOpen();
10891095
String url = nativeStartObjectBrowser(handle, null, port);
10901096
if (url != null) {
10911097
objectBrowserPort = port;
@@ -1097,6 +1103,7 @@ public String startObjectBrowser(int port) {
10971103
@Nullable
10981104
public String startObjectBrowser(String urlToBindTo) {
10991105
verifyObjectBrowserNotRunning();
1106+
checkOpen();
11001107
int port;
11011108
try {
11021109
port = new URL(urlToBindTo).getPort(); // Gives -1 if not available
@@ -1116,6 +1123,7 @@ public synchronized boolean stopObjectBrowser() {
11161123
throw new IllegalStateException("ObjectBrowser has not been started before");
11171124
}
11181125
objectBrowserPort = 0;
1126+
checkOpen();
11191127
return nativeStopObjectBrowser(handle);
11201128
}
11211129

@@ -1141,6 +1149,7 @@ private void verifyObjectBrowserNotRunning() {
11411149
* This for example allows central error handling or special logging for database-related exceptions.
11421150
*/
11431151
public void setDbExceptionListener(@Nullable DbExceptionListener dbExceptionListener) {
1152+
checkOpen();
11441153
nativeSetDbExceptionListener(handle, dbExceptionListener);
11451154
}
11461155

@@ -1179,10 +1188,12 @@ public TxCallback<?> internalFailedReadTxAttemptCallback() {
11791188
}
11801189

11811190
void setDebugFlags(int debugFlags) {
1191+
checkOpen();
11821192
nativeSetDebugFlags(handle, debugFlags);
11831193
}
11841194

11851195
long panicModeRemoveAllObjects(int entityId) {
1196+
checkOpen();
11861197
return nativePanicModeRemoveAllObjects(handle, entityId);
11871198
}
11881199

Collapse file

‎tests/objectbox-java-test/src/test/java/io/objectbox/exception/ExceptionTest.java‎

Copy file name to clipboardExpand all lines: tests/objectbox-java-test/src/test/java/io/objectbox/exception/ExceptionTest.java
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ public void exceptionListener_null_works() {
4545
store.setDbExceptionListener(null);
4646
}
4747

48-
@Test
49-
public void exceptionListener_closedStore_works() {
48+
@Test(expected = IllegalStateException.class)
49+
public void exceptionListener_closedStore_throws() {
5050
store.close();
5151
store.setDbExceptionListener(e -> System.out.println("This is never called"));
5252
}
5353

54-
private static AtomicInteger weakRefListenerCalled = new AtomicInteger(0);
54+
private static final AtomicInteger weakRefListenerCalled = new AtomicInteger(0);
5555

5656
@Test
5757
public void exceptionListener_noLocalRef_works() throws InterruptedException {

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.