[ 
https://issues.apache.org/jira/browse/DERBY-6885?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15256006#comment-15256006
 ] 

Knut Anders Hatlen commented on DERBY-6885:
-------------------------------------------

Thanks for reviewing the patch, Bryan.

The PrivilegedAction must still be declared as PrivilegedAction<Boolean> 
because Java doesn't allow primitive types as type parameters in generic types.

The success variable doesn't really have to be a boolean, it could just as well 
have continued to be a Boolean. The only difference is whether the implicit 
conversion from Boolean to boolean happens in the assignment or in the if 
statement. The two alternatives are essentially equivalent. I don't see any 
particular benefits one way or the other.

It is possible to eliminate the success variable. The compiler accepts the last 
code snippet in your comment, and will generate a call to booleanValue() on the 
Boolean returned by doPrivileged(). We can even eliminate the pa variable, like 
this:

{code}
        if (!AccessController.doPrivileged((PrivilegedAction<Boolean>)
                () -> FileUtil.copyFile(dataFactory.getStorageFactory(),
                                        from, to))) {
            // ....
        }
{code}

I can make this change if you prefer the shorter version.

> Remove ReuseFactory
> -------------------
>
>                 Key: DERBY-6885
>                 URL: https://issues.apache.org/jira/browse/DERBY-6885
>             Project: Derby
>          Issue Type: Improvement
>          Components: Services
>    Affects Versions: 10.13.0.0
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>            Priority: Minor
>         Attachments: d6885.diff
>
>
> ReuseFactory used to help reduce object allocations when converting 
> numbers/booleans from primitive types to object types. After DERBY-2383 and 
> DERBY-6230, the ReuseFactory methods are just wrappers around standard 
> library methods such as Integer.valueOf() and Long.valueOf().
> Callers could just as easily call the corresponding valueOf() method 
> directly, or rely on auto-boxing. Both ways use the same cache as 
> ReuseFactory currently does, so ReuseFactory has no purpose anymore.
> One exception: ReuseFactory.getZeroLenByteArray() is still used and provides 
> value, as it avoids the allocation cost when an empty byte array is needed. 
> The ArrayUtil class is probably just as good a home for it, so I propose we 
> move it there and remove the ReuseFactory class.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to