From eee1ff965143910eb52895af471b260564938db6 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 9 Nov 2023 11:07:34 +0200 Subject: [PATCH] enable unchecked lint for our java code and annotate where necessary, mostly just suppressing the warnings Change-Id: I8e39d797cde6c7c3f4e3e1bd93a128965ecec81d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159205 Tested-by: Jenkins Reviewed-by: Noel Grandin --- .../java/com/sun/star/bridges/jni_uno/JNI_proxy.java | 2 +- dbaccess/qa/complex/dbaccess/DatabaseDocument.java | 1 + dbaccess/qa/complex/dbaccess/RowSet.java | 8 ++++---- .../qa/complex/dbaccess/SingleSelectQueryComposer.java | 2 +- dbaccess/qa/complex/dbaccess/TestCase.java | 2 +- .../sun/star/lib/uno/helper/InterfaceContainer_Test.java | 1 + qadevOOo/runner/util/ValueChanger.java | 1 + qadevOOo/tests/java/ifc/beans/_XFastPropertySet.java | 3 ++- qadevOOo/tests/java/ifc/beans/_XMultiPropertySet.java | 1 + qadevOOo/tests/java/ifc/io/_XDataInputStream.java | 4 ++-- qadevOOo/tests/java/ifc/io/_XDataOutputStream.java | 1 + qadevOOo/tests/java/ifc/sdbc/_XParameters.java | 1 + qadevOOo/tests/java/ifc/sdbc/_XRow.java | 1 + qadevOOo/tests/java/ifc/sdbc/_XRowUpdate.java | 1 + .../tests/java/ifc/view/_XMultiSelectionSupplier.java | 1 + qadevOOo/tests/java/ifc/view/_XSelectionSupplier.java | 1 + ridljar/com/sun/star/lib/util/WeakMap.java | 4 ++++ sfx2/qa/complex/sfx2/UndoManager.java | 1 + solenv/gbuild/JavaClassSet.mk | 3 ++- wizards/com/sun/star/wizards/ui/ButtonList.java | 1 + 20 files changed, 29 insertions(+), 11 deletions(-) diff --git a/bridges/source/jni_uno/java/com/sun/star/bridges/jni_uno/JNI_proxy.java b/bridges/source/jni_uno/java/com/sun/star/bridges/jni_uno/JNI_proxy.java index 12817e57eeda..200f664f32c3 100644 --- a/bridges/source/jni_uno/java/com/sun/star/bridges/jni_uno/JNI_proxy.java +++ b/bridges/source/jni_uno/java/com/sun/star/bridges/jni_uno/JNI_proxy.java @@ -139,7 +139,7 @@ public final class JNI_proxy implements java.lang.reflect.InvocationHandler public static java.lang.reflect.Constructor get_proxy_ctor( Class clazz ) throws Throwable { - Class proxy_class = java.lang.reflect.Proxy.getProxyClass( + Class proxy_class = java.lang.reflect.Proxy.getProxyClass( s_classloader, new Class [] { clazz, IQueryInterface.class, com.sun.star.lib.uno.Proxy.class } ); diff --git a/dbaccess/qa/complex/dbaccess/DatabaseDocument.java b/dbaccess/qa/complex/dbaccess/DatabaseDocument.java index 5bd28053b77c..3087ad6374c2 100644 --- a/dbaccess/qa/complex/dbaccess/DatabaseDocument.java +++ b/dbaccess/qa/complex/dbaccess/DatabaseDocument.java @@ -174,6 +174,7 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document. }; } + @SuppressWarnings("unchecked") public void dispose() { final EventObject event = new EventObject(this); diff --git a/dbaccess/qa/complex/dbaccess/RowSet.java b/dbaccess/qa/complex/dbaccess/RowSet.java index 4c5fcc6da793..ed42a271b46f 100644 --- a/dbaccess/qa/complex/dbaccess/RowSet.java +++ b/dbaccess/qa/complex/dbaccess/RowSet.java @@ -365,7 +365,7 @@ public class RowSet extends TestCase m_rowSet.addRowSetListener(pRow); // do some movements to check if we got all notifications - final Class cResSet = Class.forName("com.sun.star.sdbc.XResultSet"); + final Class cResSet = Class.forName("com.sun.star.sdbc.XResultSet"); final boolean moves[] = new boolean[9]; for (int i = 0; i < moves.length; ++i) { @@ -399,7 +399,7 @@ public class RowSet extends TestCase testCursorMove(m_resultSet, cResSet.getMethod(NEXT, (Class[]) null), pRow, moves, null); moves[RowSetEventListener.IS_MODIFIED] = false; - final Class cupd = Class.forName("com.sun.star.sdbc.XResultSetUpdate"); + final Class cupd = Class.forName("com.sun.star.sdbc.XResultSetUpdate"); final XResultSetUpdate upd = UnoRuntime.queryInterface( XResultSetUpdate.class, m_resultSet ); testCursorMove(upd, cupd.getMethod("moveToInsertRow", (Class[]) null), pRow, moves, null); @@ -445,7 +445,7 @@ public class RowSet extends TestCase moves[RowSetEventListener.COLUMN_VALUE] = true; moves[RowSetEventListener.CURSOR_MOVED] = true; - final Class cloc = Class.forName("com.sun.star.sdbcx.XRowLocate"); + final Class cloc = Class.forName("com.sun.star.sdbcx.XRowLocate"); m_resultSet.first(); final Object bookmark = m_rowLocate.getBookmark(); m_resultSet.next(); @@ -470,7 +470,7 @@ public class RowSet extends TestCase moves[RowSetEventListener.APPROVE_ROW_CHANGE] = true; moves[RowSetEventListener.ROW_CHANGED] = true; moves[RowSetEventListener.ROW_COUNT] = true; - final Class cdelRows = Class.forName("com.sun.star.sdbcx.XDeleteRows"); + final Class cdelRows = Class.forName("com.sun.star.sdbcx.XDeleteRows"); ctemp[0] = Object[].class; final XDeleteRows delRows = UnoRuntime.queryInterface( XDeleteRows.class, m_resultSet ); final Object bookmarks[] = new Object[5]; diff --git a/dbaccess/qa/complex/dbaccess/SingleSelectQueryComposer.java b/dbaccess/qa/complex/dbaccess/SingleSelectQueryComposer.java index 2d05030b7e83..656b44d00c04 100644 --- a/dbaccess/qa/complex/dbaccess/SingleSelectQueryComposer.java +++ b/dbaccess/qa/complex/dbaccess/SingleSelectQueryComposer.java @@ -81,7 +81,7 @@ public class SingleSelectQueryComposer extends CRMBasedTestCase String realValue = null; try { - final Class composerClass = m_composer.getClass(); + final Class composerClass = m_composer.getClass(); final Method attributeGetter = composerClass.getMethod("get" + _attributeName, new Class[] { }); diff --git a/dbaccess/qa/complex/dbaccess/TestCase.java b/dbaccess/qa/complex/dbaccess/TestCase.java index a9768e7b47a2..8c284ae51f40 100644 --- a/dbaccess/qa/complex/dbaccess/TestCase.java +++ b/dbaccess/qa/complex/dbaccess/TestCase.java @@ -119,7 +119,7 @@ public abstract class TestCase private void assureException( final String _message, final Object _object, final String _methodName, final Class[] _argClasses, final Object[] _methodArgs, final Class _expectedExceptionClass ) { - Class objectClass = _object.getClass(); + Class objectClass = _object.getClass(); boolean noExceptionAllowed = ( _expectedExceptionClass == null ); diff --git a/javaunohelper/test/com/sun/star/lib/uno/helper/InterfaceContainer_Test.java b/javaunohelper/test/com/sun/star/lib/uno/helper/InterfaceContainer_Test.java index a406b84d457e..e3e9266afd4d 100644 --- a/javaunohelper/test/com/sun/star/lib/uno/helper/InterfaceContainer_Test.java +++ b/javaunohelper/test/com/sun/star/lib/uno/helper/InterfaceContainer_Test.java @@ -626,6 +626,7 @@ public class InterfaceContainer_Test it.previous(); } + @SuppressWarnings("unchecked") @Test public void ListIterator_add() throws Exception { logger.log(Level.INFO, "Testing ListIterator.add()"); diff --git a/qadevOOo/runner/util/ValueChanger.java b/qadevOOo/runner/util/ValueChanger.java index 998bd9fce131..f6a58dd2b8c0 100644 --- a/qadevOOo/runner/util/ValueChanger.java +++ b/qadevOOo/runner/util/ValueChanger.java @@ -1077,6 +1077,7 @@ public class ValueChanger { return result; } + @SuppressWarnings("unchecked") private static T copyStruct(T value) { Class clazz = (Class) value.getClass(); T newValue; diff --git a/qadevOOo/tests/java/ifc/beans/_XFastPropertySet.java b/qadevOOo/tests/java/ifc/beans/_XFastPropertySet.java index a7821ba2b88d..12f4a1bdc282 100644 --- a/qadevOOo/tests/java/ifc/beans/_XFastPropertySet.java +++ b/qadevOOo/tests/java/ifc/beans/_XFastPropertySet.java @@ -73,7 +73,8 @@ public class _XFastPropertySet extends MultiMethodTest { /** * Retrieves relation. */ - @Override + @SuppressWarnings("unchecked") + @Override protected void before() { exclude = (Set) tEnv.getObjRelation("XFastPropertySet.ExcludeProps") ; if (exclude == null) { diff --git a/qadevOOo/tests/java/ifc/beans/_XMultiPropertySet.java b/qadevOOo/tests/java/ifc/beans/_XMultiPropertySet.java index e23e3845d867..052e58843679 100644 --- a/qadevOOo/tests/java/ifc/beans/_XMultiPropertySet.java +++ b/qadevOOo/tests/java/ifc/beans/_XMultiPropertySet.java @@ -78,6 +78,7 @@ public class _XMultiPropertySet extends MultiMethodTest { /** * Initializes some fields. */ + @SuppressWarnings("unchecked") @Override public void before() { exclProps = (Set) tEnv.getObjRelation("XMultiPropertySet.ExcludeProps"); diff --git a/qadevOOo/tests/java/ifc/io/_XDataInputStream.java b/qadevOOo/tests/java/ifc/io/_XDataInputStream.java index 5ab320fa526e..e451b8e7eb05 100644 --- a/qadevOOo/tests/java/ifc/io/_XDataInputStream.java +++ b/qadevOOo/tests/java/ifc/io/_XDataInputStream.java @@ -76,12 +76,12 @@ public class _XDataInputStream extends MultiMethodTest { * data of different types and fills the appropriate variables. * @throws StatusException If one of relations not found. */ + @SuppressWarnings("unchecked") @Override public void before(){ XInterface x = (XInterface)tEnv.getObjRelation("StreamWriter") ; - oStream = UnoRuntime.queryInterface( - XDataOutputStream.class, x); + oStream = UnoRuntime.queryInterface(XDataOutputStream.class, x); List data = (List) tEnv.getObjRelation("StreamData") ; if (data == null || oStream == null) { throw new StatusException(Status.failed("Object relation not found.")); diff --git a/qadevOOo/tests/java/ifc/io/_XDataOutputStream.java b/qadevOOo/tests/java/ifc/io/_XDataOutputStream.java index 3ea11193d58b..3395ba9d61c5 100644 --- a/qadevOOo/tests/java/ifc/io/_XDataOutputStream.java +++ b/qadevOOo/tests/java/ifc/io/_XDataOutputStream.java @@ -56,6 +56,7 @@ public class _XDataOutputStream extends MultiMethodTest { * If relation or data of some type in stream not found then * tests of corresponding methods are skipped. */ + @SuppressWarnings("unchecked") @Override public void before() throws RuntimeException { diff --git a/qadevOOo/tests/java/ifc/sdbc/_XParameters.java b/qadevOOo/tests/java/ifc/sdbc/_XParameters.java index 4284931fefee..31a5e6d4b0ad 100644 --- a/qadevOOo/tests/java/ifc/sdbc/_XParameters.java +++ b/qadevOOo/tests/java/ifc/sdbc/_XParameters.java @@ -99,6 +99,7 @@ public class _XParameters extends MultiMethodTest { /** * Gets object relation */ + @SuppressWarnings("unchecked") @Override public void before() { data = (List) tEnv.getObjRelation("XParameters.ParamValues") ; diff --git a/qadevOOo/tests/java/ifc/sdbc/_XRow.java b/qadevOOo/tests/java/ifc/sdbc/_XRow.java index 70a60b0cf34c..e1babb0760b6 100644 --- a/qadevOOo/tests/java/ifc/sdbc/_XRow.java +++ b/qadevOOo/tests/java/ifc/sdbc/_XRow.java @@ -100,6 +100,7 @@ public class _XRow extends MultiMethodTest { /** * Retrieves object relation first. */ + @SuppressWarnings("unchecked") @Override public void before() { data = (List) tEnv.getObjRelation("CurrentRowData") ; diff --git a/qadevOOo/tests/java/ifc/sdbc/_XRowUpdate.java b/qadevOOo/tests/java/ifc/sdbc/_XRowUpdate.java index e57b2f062d6e..88122513cc88 100644 --- a/qadevOOo/tests/java/ifc/sdbc/_XRowUpdate.java +++ b/qadevOOo/tests/java/ifc/sdbc/_XRowUpdate.java @@ -99,6 +99,7 @@ public class _XRowUpdate extends MultiMethodTest { /** * Gets relations. */ + @SuppressWarnings("unchecked") @Override public void before() { rowData = (List) tEnv.getObjRelation("CurrentRowData") ; diff --git a/qadevOOo/tests/java/ifc/view/_XMultiSelectionSupplier.java b/qadevOOo/tests/java/ifc/view/_XMultiSelectionSupplier.java index c7009a88ab18..310e37e94ed3 100644 --- a/qadevOOo/tests/java/ifc/view/_XMultiSelectionSupplier.java +++ b/qadevOOo/tests/java/ifc/view/_XMultiSelectionSupplier.java @@ -54,6 +54,7 @@ public class _XMultiSelectionSupplier extends MultiMethodTest { Object[] selections = null; Comparator ObjCompare = null; + @SuppressWarnings("unchecked") @Override protected void before() { selections = (Object[])tEnv.getObjRelation("Selections"); diff --git a/qadevOOo/tests/java/ifc/view/_XSelectionSupplier.java b/qadevOOo/tests/java/ifc/view/_XSelectionSupplier.java index 0fa919d944b1..cc6bc4120a7c 100644 --- a/qadevOOo/tests/java/ifc/view/_XSelectionSupplier.java +++ b/qadevOOo/tests/java/ifc/view/_XSelectionSupplier.java @@ -53,6 +53,7 @@ public class _XSelectionSupplier extends MultiMethodTest { Object[] selections = null; Comparator ObjCompare = null; + @SuppressWarnings("unchecked") @Override protected void before() { selections = (Object[])tEnv.getObjRelation("Selections"); diff --git a/ridljar/com/sun/star/lib/util/WeakMap.java b/ridljar/com/sun/star/lib/util/WeakMap.java index f3b3b55a356b..4d63d27286a3 100644 --- a/ridljar/com/sun/star/lib/util/WeakMap.java +++ b/ridljar/com/sun/star/lib/util/WeakMap.java @@ -165,6 +165,7 @@ public final class WeakMap implements Map { * @return previous value associated with the specified key, or * null if there was no mapping for the key */ + @SuppressWarnings("unchecked") public Object /*WeakReference*/ put(/*K*/ Object key, /*V*/ Object value) { cleanUp(); return map.put((K) key, new Entry((K) key, (V) value, queue)); @@ -193,6 +194,7 @@ public final class WeakMap implements Map { * must be plain objects, which are then wrapped in instances of * WeakReference. */ + @SuppressWarnings("unchecked") public void putAll(Map/**/ m) { cleanUp(); for (Iterator> i = m.entrySet().iterator(); i.hasNext();) { @@ -267,6 +269,7 @@ public final class WeakMap implements Map { * @return the referent of the specified WeakReference, or * null if ref is null */ + @SuppressWarnings("unchecked") public static T getValue(Object /*WeakReference*/ ref) { return ref == null ? null : ((WeakReference) ref).get(); } @@ -277,6 +280,7 @@ public final class WeakMap implements Map { * (Specifically, iterating over the collections returned by those * methods), as non-modifying methods might modify the underlying map. **/ + @SuppressWarnings("unchecked") private void cleanUp() { for (;;) { Entry e = (Entry) queue.poll(); diff --git a/sfx2/qa/complex/sfx2/UndoManager.java b/sfx2/qa/complex/sfx2/UndoManager.java index 12f13ada10a1..ea1a3496519f 100644 --- a/sfx2/qa/complex/sfx2/UndoManager.java +++ b/sfx2/qa/complex/sfx2/UndoManager.java @@ -1384,6 +1384,7 @@ public class UndoManager return new String[] { getCallbackComponentServiceName() }; } + @SuppressWarnings("unchecked") public void dispose() { final EventObject event = new EventObject( this ); diff --git a/solenv/gbuild/JavaClassSet.mk b/solenv/gbuild/JavaClassSet.mk index 087c79750d00..84fbcc13c32d 100644 --- a/solenv/gbuild/JavaClassSet.mk +++ b/solenv/gbuild/JavaClassSet.mk @@ -20,7 +20,8 @@ gb_JavaClassSet_JAVACCOMMAND = $(ICECREAM_RUN) $(JAVACOMPILER) $(JAVACFLAGS) \ -encoding utf8 \ --release $(1) \ - -Xlint:-options + -Xlint:-options \ + -Xlint:unchecked gb_JavaClassSet_JAVACDEBUG := diff --git a/wizards/com/sun/star/wizards/ui/ButtonList.java b/wizards/com/sun/star/wizards/ui/ButtonList.java index 522768bf8c07..a129fe97c8fc 100644 --- a/wizards/com/sun/star/wizards/ui/ButtonList.java +++ b/wizards/com/sun/star/wizards/ui/ButtonList.java @@ -375,6 +375,7 @@ public class ButtonList implements XItemEventBroadcaster, XActionListener /** Notifies all registered listeners about the event. * */ + @SuppressWarnings("unchecked") private void fireItemSelected() { java.util.ArrayList list;