From f95d379de9c9ba90714aee4faab6039b0b78ac5e Mon Sep 17 00:00:00 2001 From: Cristian Turlica Date: Tue, 5 Feb 2019 15:06:24 +0200 Subject: [PATCH] REPO-4102: MNT-20213: Unable to run using Java 8 - explicit cast for compatibility with covariant return type on JDK 9's ByteBuffer --- .../search/impl/lucene/index/IndexInfo.java | 63 +++++----- .../transfer/HttpClientTransmitterImpl.java | 5 +- .../AbstractWritableContentStoreTest.java | 111 +++++++++--------- .../repo/content/filestore/FileIOTest.java | 57 ++++----- 4 files changed, 121 insertions(+), 115 deletions(-) diff --git a/src/main/java/org/alfresco/repo/search/impl/lucene/index/IndexInfo.java b/src/main/java/org/alfresco/repo/search/impl/lucene/index/IndexInfo.java index 7e3208afe2..8861b39dac 100644 --- a/src/main/java/org/alfresco/repo/search/impl/lucene/index/IndexInfo.java +++ b/src/main/java/org/alfresco/repo/search/impl/lucene/index/IndexInfo.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ package org.alfresco.repo.search.impl.lucene.index; import java.io.BufferedInputStream; @@ -36,6 +36,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.RandomAccessFile; import java.io.UnsupportedEncodingException; +import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; @@ -2428,10 +2429,10 @@ public class IndexInfo implements IndexMonitor { buffer = ByteBuffer.wrap(new byte[8]); channel.read(buffer); - buffer.position(0); + ((Buffer) buffer).position(0); } - buffer.position(0); + ((Buffer) buffer).position(0); long onDiskVersion = buffer.getLong(); return (version == onDiskVersion); } @@ -2455,10 +2456,10 @@ public class IndexInfo implements IndexMonitor { buffer = ByteBuffer.wrap(new byte[(int) channel.size()]); channel.read(buffer); - buffer.position(0); + ((Buffer) buffer).position(0); } - buffer.position(0); + ((Buffer) buffer).position(0); long onDiskVersion = buffer.getLong(); if (version != onDiskVersion) { @@ -2604,7 +2605,7 @@ public class IndexInfo implements IndexMonitor buffer = ByteBuffer.wrap(new byte[(int) size]); } - buffer.position(0); + ((Buffer) buffer).position(0); buffer.putLong(version); CRC32 crc32 = new CRC32(); @@ -2647,7 +2648,7 @@ public class IndexInfo implements IndexMonitor } else { - buffer.rewind(); + ((Buffer) buffer).rewind(); channel.position(0); channel.write(buffer); } diff --git a/src/main/java/org/alfresco/repo/transfer/HttpClientTransmitterImpl.java b/src/main/java/org/alfresco/repo/transfer/HttpClientTransmitterImpl.java index 5ddbe41b5d..2d8b41683b 100644 --- a/src/main/java/org/alfresco/repo/transfer/HttpClientTransmitterImpl.java +++ b/src/main/java/org/alfresco/repo/transfer/HttpClientTransmitterImpl.java @@ -30,6 +30,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; @@ -817,7 +818,7 @@ public class HttpClientTransmitterImpl implements TransferTransmitter while (src.read(buffer) != -1) { // prepare the buffer to be drained - buffer.flip(); + ((Buffer) buffer).flip(); // write to the channel, may block dest.write(buffer); @@ -827,7 +828,7 @@ public class HttpClientTransmitterImpl implements TransferTransmitter } // EOF will leave buffer in fill state - buffer.flip(); + ((Buffer) buffer).flip(); // make sure the buffer is fully drained. while (buffer.hasRemaining()) diff --git a/src/test/java/org/alfresco/repo/content/AbstractWritableContentStoreTest.java b/src/test/java/org/alfresco/repo/content/AbstractWritableContentStoreTest.java index 523dc6a670..e04eda546f 100644 --- a/src/test/java/org/alfresco/repo/content/AbstractWritableContentStoreTest.java +++ b/src/test/java/org/alfresco/repo/content/AbstractWritableContentStoreTest.java @@ -1,56 +1,57 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ package org.alfresco.repo.content; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; -import java.nio.channels.ReadableByteChannel; -import java.util.Locale; - -import org.alfresco.service.cmr.repository.ContentIOException; -import org.alfresco.service.cmr.repository.ContentReader; -import org.alfresco.service.cmr.repository.ContentStreamListener; -import org.alfresco.service.cmr.repository.ContentWriter; -import org.alfresco.util.TempFileProvider; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.Buffer; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.channels.ReadableByteChannel; +import java.util.Locale; + +import org.alfresco.service.cmr.repository.ContentIOException; +import org.alfresco.service.cmr.repository.ContentReader; +import org.alfresco.service.cmr.repository.ContentStreamListener; +import org.alfresco.service.cmr.repository.ContentWriter; +import org.alfresco.util.TempFileProvider; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * Abstract base class that provides a set of tests for implementations @@ -433,10 +434,10 @@ public abstract class AbstractWritableContentStoreTest extends AbstractReadOnlyC // attempt to delete the content boolean deleted = store.delete(contentUrl); - // close the reader stream - if(is != null) + // close the reader stream + if(is != null) { - is.close(); + is.close(); } // get a fresh reader @@ -731,7 +732,7 @@ public abstract class AbstractWritableContentStoreTest extends AbstractReadOnlyC int count = fileChannel.read(buffer); assertEquals("Incorrect number of bytes read", bytes.length, count); // transfer back to array - buffer.rewind(); + ((Buffer) buffer).rewind(); buffer.get(bytes); String checkContent = new String(bytes); assertEquals("Content read failure", content, checkContent); diff --git a/src/test/java/org/alfresco/repo/content/filestore/FileIOTest.java b/src/test/java/org/alfresco/repo/content/filestore/FileIOTest.java index fcf0d8c412..dad20b7db2 100644 --- a/src/test/java/org/alfresco/repo/content/filestore/FileIOTest.java +++ b/src/test/java/org/alfresco/repo/content/filestore/FileIOTest.java @@ -1,34 +1,35 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ package org.alfresco.repo.content.filestore; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.OutputStream; +import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.util.HashSet; @@ -86,8 +87,10 @@ public class FileIOTest extends TestCase int countB = 0; do { - countA = channelA.read((ByteBuffer)bufferA.clear()); - countB = channelB.read((ByteBuffer)bufferB.clear()); + ((Buffer) bufferA).clear(); + countA = channelA.read(bufferA); + ((Buffer) bufferB).clear(); + countB = channelB.read(bufferB); assertEquals("Should read same number of bytes", countA, countB); } while (countA > 6);