[ 
https://issues.apache.org/jira/browse/DERBY-5840?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Knut Anders Hatlen updated DERBY-5840:
--------------------------------------

    Attachment: derby-5840-15-aa-more-suppressions.diff

The attached patch derby-5840-15-aa-more-suppressions.diff removes more 
@SuppressWarnings annotations:

- java/engine/org/apache/derby/iapi/services/context/ContextService.java:

The suppressed warnings were caused by casts from Object to 
Stack<ContextManager>, and casts to generic types cause unchecked warnings as 
they cannot be checked at run-time because of type erasure.

These casts were needed because the stacks live in a ThreadLocal<Object> 
instance rather than a ThreadLocal<Stack<ContextManager>>, because of an 
optimization that prevents allocation of a Stack object until the second 
ContextManager is put on the stack. The code would have been simpler, and the 
warnings would go away, if the ThreadLocal always contained a Stack. But for 
now I'm going to assume the optimization is worth the extra complexity, and 
keep the ThreadLocal as a ThreadLocal<Object>.

To prevent the warnings, the patch changes ContextService so that it puts the 
context managers in a specialized sub-class of Stack. The class itself is 
actually empty:

    /** Specialized stack class that contains context managers. */
    private static class ContextManagerStack extends Stack<ContextManager> {
        // The class is empty. Its primary purpose is to allow type-safe casts
        // from Object, which are needed because the stacks live in a
        // ThreadLocal<Object> rather than ThreadLocal<Stack<ContextManager>>.
        // Casts from Object to Stack<ContextManager> will cause an unchecked
        // conversion warning, whereas casts from Object to ContextManagerStack
        // won't.
    }

Casts to ContextManagerStack will not cause warnings, since it's not a generic 
type and doesn't suffer from type erasure. However, since it extends 
Stack<ContextManager>, it can be used just like a Stack<ContextManager> 
instance. For example, its pop() method returns a ContextManager without any 
cast needed, and the compiler will give an error if the argument to push() is 
not a ContextManager.

- java/engine/org/apache/derby/impl/services/jmx/JMXManagementService.java:

The suppressed warning was caused by a call to StandardMBean's constructor, 
which has a generic signature (T obj, Class<T> cl), whereas the actual 
arguments passed in were (Object, Class).

The patch silences the warning by generifying the signature of 
ManagementService.registerMBean(), and its implementations in 
JMXManagementService and NoManagementService, so that StandardMBean's 
constructor can be called with properly typed arguments.

- java/engine/org/apache/derby/impl/services/locks/LockSpace.java:

The suppressed warning was caused by caching HashMap<Lock,Object> instances in 
an array. Since arrays cannot have generic types, the elements in the array had 
to be cast to the generic type each time they were read, and casting to generic 
types causes unchecked conversion warnings.

The patch made LockSpace cache the HashMap objects in a collection (an 
ArrayDeque instance) instead of an array. Collections can have generic types, 
so the unsafe cast was avoided.

java/engine/org/apache/derby/vti/ForeignTableVTI.java:
java/engine/org/apache/derby/vti/VTITemplate.java:

Removed suppression of deprecation warnings on the class level, and instead 
tagged each of the deprecated methods with a Deprecated annotation.

I'm running regression tests on the patch.
                
> Clean up compiler warnings introduced by using Java 5 language features
> -----------------------------------------------------------------------
>
>                 Key: DERBY-5840
>                 URL: https://issues.apache.org/jira/browse/DERBY-5840
>             Project: Derby
>          Issue Type: Improvement
>          Components: Miscellaneous
>    Affects Versions: 10.10.1.1
>            Reporter: Rick Hillegas
>         Attachments: derby-5840-01-aa-compatibilityTests.diff, 
> derby-5840-02-aa-compatibilityTests-again.diff.txt, 
> derby-5840-03-aa-drda.diff, derby-5840-03-ab-drda.diff, 
> derby-5840-04-aa-client-level.diff, derby-5840-05-aa-client-deprecation.diff, 
> derby-5840-06-aa-jdbc3-stubs.diff, derby-5840-07-aa-drda-for-each.diff, 
> derby-5840-08-aa-jdbc3-embedded.diff, 
> derby-5840-09-aa-test-deprecation-and-unchecked.diff, 
> derby-5840-10-aa-derbynet-perf-system.diff, 
> derby-5840-11-aa-engine-i18n-store-tools.diff, derby-5840-12-aa-jdbcapi.diff, 
> derby-5840-13-aa.diff, derby-5840-13-aa-remove-suppression.diff, 
> derby-5840-14-aa-bigdecimal.diff, derby-5840-15-aa-more-suppressions.diff
>
>
> Using Java 5 language features forces us to compile code at level 5 or 
> higher. At this level, the compiler raises warnings not seen at lower levels. 
> This issue is a place to discuss and attach cleanup to eliminate these 
> warnings.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to