Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v5
- name: Set up JDK 17
uses: actions/setup-java@v2
uses: actions/setup-java@v5
with:
java-version: '17'
distribution: 'temurin'
Expand Down
23 changes: 11 additions & 12 deletions dump/src/util/dump/Dump.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.security.AccessControlException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -329,7 +328,7 @@ public Dump( Class<? extends E> beanClass, ObjectStreamProvider streamProvider,
public void add( E o ) throws IOException {
synchronized ( this ) {
if ( !_mode.contains(DumpAccessFlag.add) ) {
throw new AccessControlException("Add operation not allowed with current modes.");
throw new IllegalStateException("Add operation not allowed with current modes.");
}
assertOpen();
for ( DumpIndex<E> index : _indexes ) {
Expand Down Expand Up @@ -432,7 +431,7 @@ public void close() throws IOException {
*/
public E delete( long pos ) {
if ( !_mode.contains(DumpAccessFlag.delete) ) {
throw new AccessControlException("Delete operation not allowed with current modes.");
throw new IllegalStateException("Delete operation not allowed with current modes.");
}

synchronized ( this ) {
Expand Down Expand Up @@ -490,7 +489,7 @@ public void flush() throws IOException {
*/
public void flushMeta() throws IOException {
if ( isReadonly() ) {
throw new AccessControlException("Flushing meta-data not allowed in read-only mode.");
throw new IllegalStateException("Flushing meta-data not allowed in read-only mode.");
}

writeMeta();
Expand All @@ -509,7 +508,7 @@ public void flushMeta() throws IOException {
@Nullable
public E get( long pos ) {
if ( !_mode.contains(DumpAccessFlag.read) ) {
throw new AccessControlException("Get operation not allowed with current modes.");
throw new IllegalStateException("Get operation not allowed with current modes.");
}

synchronized ( this ) {
Expand Down Expand Up @@ -772,7 +771,7 @@ public E update( long pos, E newItem ) throws IOException {

if ( indexesUpdatable ) {
if ( !_mode.contains(DumpAccessFlag.updateInPlace) ) {
throw new AccessControlException("Update in place operation not allowed with current modes.");
throw new IllegalStateException("Update in place operation not allowed with current modes.");
}
overwrite(pos, nb);
for ( DumpIndex<E> index : _indexes ) {
Expand All @@ -794,7 +793,7 @@ public E update( long pos, E newItem ) throws IOException {

// overwriting was not possible -> delete old version and add new version
if ( !_mode.contains(DumpAccessFlag.updateOutOfPlace) ) {
throw new AccessControlException("Update out of place operation not allowed with current modes.");
throw new IllegalStateException("Update out of place operation not allowed with current modes.");
}

E old = delete(pos);
Expand Down Expand Up @@ -956,7 +955,7 @@ protected boolean shouldBePruned() {

void addIndex( DumpIndex<E> index ) {
if ( !_mode.contains(DumpAccessFlag.indices) ) {
throw new AccessControlException("Using indices is not allowed with current modes.");
throw new IllegalStateException("Using indices is not allowed with current modes.");
}

assertOpen();
Expand Down Expand Up @@ -1076,7 +1075,7 @@ void writeDictionary() throws IOException {

void writeMeta() throws IOException {
if ( isReadonly() ) {
throw new AccessControlException("Writing meta-data not allowed in read-only mode.");
throw new IllegalStateException("Writing meta-data not allowed in read-only mode.");
}

getMetaRAF().seek(0);
Expand Down Expand Up @@ -1122,10 +1121,10 @@ private void checkVersion() throws IOException {
_log.warn(msg, dumpVersion, codeVersion, "not doing anything due to read-only mode");
switch ( getOnIncompatibleVersion() ) {
case RenameDump: {
throw new AccessControlException("Renaming Dump is not allowed in read-only mode.");
throw new IllegalStateException("Renaming Dump is not allowed in read-only mode.");
}
case DeleteDump: {
throw new AccessControlException("Deleting Dump is not allowed in read-only mode.");
throw new IllegalStateException("Deleting Dump is not allowed in read-only mode.");
}
case RewriteDump: {
// do nothing, allowing potential readers to write the contents to some other dump in proper externalization version
Expand Down Expand Up @@ -1720,7 +1719,7 @@ private DeletionAwareDumpReader( File dumpFile, ObjectStreamProvider streamProvi
super(new ResettableBufferedInputStream(new FileInputStream(_dumpFile), 0, false), 0, streamProvider);
_sourceFile = dumpFile;
if ( !_mode.contains(DumpAccessFlag.read) ) {
throw new AccessControlException("Read operation not allowed with current modes.");
throw new IllegalStateException("Read operation not allowed with current modes.");
}
_positionAwareInputStream = (ResettableBufferedInputStream)_primitiveInputStream;
_positionAwareInputStream._lastElementBytes = new byte[1024];
Expand Down
23 changes: 11 additions & 12 deletions dump/test/util/dump/DumpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.io.FileFilter;
import java.io.IOException;
import java.nio.file.Files;
import java.security.AccessControlException;
import java.util.HashSet;
import java.util.Set;
import java.util.SortedSet;
Expand Down Expand Up @@ -47,7 +46,7 @@ public boolean accept( File f ) {
}
}

@Test(expected = AccessControlException.class)
@Test(expected = IllegalStateException.class)
public void testAddIndexWithoutAccessRight() throws Exception {
File dumpFile = new File("DumpTest.dmp");
try (Dump<Bean> dump = new Dump<>(Bean.class, dumpFile, DumpAccessFlag.add, DumpAccessFlag.delete)) {
Expand All @@ -58,26 +57,26 @@ public void testAddIndexWithoutAccessRight() throws Exception {
}
}

@Test(expected = RuntimeException.class)
public void testAddWithoutAccessRight_FileNotFoundDueToReadOnly() throws Exception {
@Test(expected = IllegalStateException.class)
public void testAddWithoutAccessRight_FileExistsDueToPreviousWriteAccess() throws Exception {
File dumpFile = new File("DumpTest.dmp");
try (Dump<Bean> dump = new Dump<>(Bean.class, dumpFile, DumpAccessFlag.add)) {
// do nothing, just initialize the file
}
try (Dump<Bean> dump = new Dump<>(Bean.class, dumpFile, DumpAccessFlag.read)) {
dump.add(new Bean(1));
}
}

@Test(expected = AccessControlException.class)
public void testAddWithoutAccessRight_FileExistsDueToPreviousWriteAccess() throws Exception {
@Test(expected = RuntimeException.class)
public void testAddWithoutAccessRight_FileNotFoundDueToReadOnly() throws Exception {
File dumpFile = new File("DumpTest.dmp");
try (Dump<Bean> dump = new Dump<>(Bean.class, dumpFile, DumpAccessFlag.add)) {
// do nothing, just initialize the file
}
try (Dump<Bean> dump = new Dump<>(Bean.class, dumpFile, DumpAccessFlag.read)) {
dump.add(new Bean(1));
}
}

@Test(expected = AccessControlException.class)
@Test(expected = IllegalStateException.class)
public void testDeleteWithoutAccessRight() throws Exception {
File dumpFile = new File("DumpTest.dmp");
try (Dump<Bean> dump = new Dump<>(Bean.class, dumpFile, DumpAccessFlag.add)) {
Expand All @@ -99,7 +98,7 @@ public void testGetWithoutAccessRight() throws Exception {
dump.get(0);
Assert.fail();
}
catch ( AccessControlException e ) {
catch ( IllegalStateException e ) {
}
finally {
dump.close();
Expand Down Expand Up @@ -336,7 +335,7 @@ public void testUpdateAll() throws IOException {
}
}

@Test(expected = AccessControlException.class)
@Test(expected = IllegalStateException.class)
public void testUpdateInPlaceWithoutAccessRight() throws Exception {
File dumpFile = new File("DumpTest.dmp");
try (Dump<Bean> dump = new Dump<>(Bean.class, dumpFile, DumpAccessFlag.add, DumpAccessFlag.delete)) {
Expand Down