diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 1c9a468..e938c50 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -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' diff --git a/dump/src/util/dump/Dump.java b/dump/src/util/dump/Dump.java index c83b7df..892fd36 100644 --- a/dump/src/util/dump/Dump.java +++ b/dump/src/util/dump/Dump.java @@ -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; @@ -329,7 +328,7 @@ public Dump( Class 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 index : _indexes ) { @@ -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 ) { @@ -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(); @@ -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 ) { @@ -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 index : _indexes ) { @@ -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); @@ -956,7 +955,7 @@ protected boolean shouldBePruned() { void addIndex( DumpIndex 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(); @@ -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); @@ -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 @@ -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]; diff --git a/dump/test/util/dump/DumpTest.java b/dump/test/util/dump/DumpTest.java index 7dc52e1..8abd506 100644 --- a/dump/test/util/dump/DumpTest.java +++ b/dump/test/util/dump/DumpTest.java @@ -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; @@ -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 dump = new Dump<>(Bean.class, dumpFile, DumpAccessFlag.add, DumpAccessFlag.delete)) { @@ -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 dump = new Dump<>(Bean.class, dumpFile, DumpAccessFlag.add)) { + // do nothing, just initialize the file + } try (Dump 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 dump = new Dump<>(Bean.class, dumpFile, DumpAccessFlag.add)) { - // do nothing, just initialize the file - } try (Dump 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 dump = new Dump<>(Bean.class, dumpFile, DumpAccessFlag.add)) { @@ -99,7 +98,7 @@ public void testGetWithoutAccessRight() throws Exception { dump.get(0); Assert.fail(); } - catch ( AccessControlException e ) { + catch ( IllegalStateException e ) { } finally { dump.close(); @@ -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 dump = new Dump<>(Bean.class, dumpFile, DumpAccessFlag.add, DumpAccessFlag.delete)) {