You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by "Zoltan Farkas (Created) (JIRA)" <ji...@apache.org> on 2011/12/10 02:48:40 UTC
[jira] [Created] (CASSANDRA-3605) Exception swallowing in Hex.java
Exception swallowing in Hex.java
--------------------------------
Key: CASSANDRA-3605
URL: https://issues.apache.org/jira/browse/CASSANDRA-3605
Project: Cassandra
Issue Type: Bug
Affects Versions: 1.0.5
Environment: all
Reporter: Zoltan Farkas
Priority: Minor
org.apache.cassandra.utils.Hex line 94:
try
{
s = stringConstructor.newInstance(0, c.length, c);
}
catch (Exception e)
{
// Swallowing as we'll just use a copying constructor
}
this code does not comply with coding standard, caught exception needs to be rethrown as RuntimeException
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Updated] (CASSANDRA-3605) Exception swallowing in Hex.java
Posted by "Zoltan Farkas (Updated) (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/CASSANDRA-3605?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Zoltan Farkas updated CASSANDRA-3605:
-------------------------------------
Issue Type: Improvement (was: Bug)
> Exception swallowing in Hex.java
> --------------------------------
>
> Key: CASSANDRA-3605
> URL: https://issues.apache.org/jira/browse/CASSANDRA-3605
> Project: Cassandra
> Issue Type: Improvement
> Affects Versions: 1.0.5
> Environment: all
> Reporter: Zoltan Farkas
> Priority: Minor
>
> org.apache.cassandra.utils.Hex line 94:
> try
> {
> s = stringConstructor.newInstance(0, c.length, c);
> }
> catch (Exception e)
> {
> // Swallowing as we'll just use a copying constructor
> }
> this code does not comply with coding standard, caught exception needs to be rethrown as RuntimeException
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (CASSANDRA-3605) Exception swallowing in
Hex.java
Posted by "Zoltan Farkas (Commented) (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/CASSANDRA-3605?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13166766#comment-13166766 ]
Zoltan Farkas commented on CASSANDRA-3605:
------------------------------------------
Hmm, as long as the JDK implementation of String does not change it would not be a bug.
I assume this optimization is quite important, the fact the the optimization actually is not used is lost...
would it be worth to add a test in a static initialization of this class to test the existence and functionality of the private constructor and log a warning that optimization is not used?
cheers!
> Exception swallowing in Hex.java
> --------------------------------
>
> Key: CASSANDRA-3605
> URL: https://issues.apache.org/jira/browse/CASSANDRA-3605
> Project: Cassandra
> Issue Type: Bug
> Affects Versions: 1.0.5
> Environment: all
> Reporter: Zoltan Farkas
> Priority: Minor
>
> org.apache.cassandra.utils.Hex line 94:
> try
> {
> s = stringConstructor.newInstance(0, c.length, c);
> }
> catch (Exception e)
> {
> // Swallowing as we'll just use a copying constructor
> }
> this code does not comply with coding standard, caught exception needs to be rethrown as RuntimeException
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Reopened] (CASSANDRA-3605) Exception swallowing in Hex.java
Posted by "Zoltan Farkas (Reopened) (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/CASSANDRA-3605?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Zoltan Farkas reopened CASSANDRA-3605:
--------------------------------------
Hi current implementation might work, but I propose the following:
private static final Logger LOG= LoggerFactory.getLogger(Hex.class);
private static final Constructor<String> stringConstructor;
static {
Constructor<String> cons = null;
try {
// test use of protected constructor
cons = getProtectedConstructor(String.class, int.class, int.class, char[].class);
char [] c = new char [] {};
cons.newInstance(0, c.length, c);
} catch (Exception ex) { // TODO improve this in java7
LOG.warn("Not Using String instantiation optimization", ex);
}
stringConstructor = cons;
}
.....
/**
* Create a String from a char array with zero-copy (if available), using reflection to access a package-protected constructor of String.
* */
public static String wrapCharArray(char[] c)
{
if (c == null)
return null;
String s = null;
if (stringConstructor != null)
{
try
{
s = stringConstructor.newInstance(0, c.length, c);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
return s == null ? new String(c) : s;
}
/**
* Used to get access to protected/private constructor of the specified class
* @param klass - name of the class
* @param paramTypes - types of the constructor parameters
* @return Constructor if successful, null if the constructor cannot be
* accessed
*/
public static Constructor getProtectedConstructor(Class klass, Class... paramTypes) throws NoSuchMethodException
{
Constructor c;
c = klass.getDeclaredConstructor(paramTypes);
c.setAccessible(true);
return c;
}
This implementation has 2 advantages:
1. Exception is not lost, and we know the fact that the optimization does not work.
2. In case the optimization does not work performance will be an order of magnitude better due to the fact that Exceptions will not be created at every string allocation attempt.
let me know if you have any questions
> Exception swallowing in Hex.java
> --------------------------------
>
> Key: CASSANDRA-3605
> URL: https://issues.apache.org/jira/browse/CASSANDRA-3605
> Project: Cassandra
> Issue Type: Improvement
> Affects Versions: 1.0.5
> Environment: all
> Reporter: Zoltan Farkas
> Priority: Minor
>
> org.apache.cassandra.utils.Hex line 94:
> try
> {
> s = stringConstructor.newInstance(0, c.length, c);
> }
> catch (Exception e)
> {
> // Swallowing as we'll just use a copying constructor
> }
> this code does not comply with coding standard, caught exception needs to be rethrown as RuntimeException
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Resolved] (CASSANDRA-3605) Exception swallowing in Hex.java
Posted by "Jonathan Ellis (Resolved) (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/CASSANDRA-3605?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Jonathan Ellis resolved CASSANDRA-3605.
---------------------------------------
Resolution: Invalid
As the comment notes, this exception is handled by the post-try block null check. Throwing a RuntimeException instead would create a bug.
> Exception swallowing in Hex.java
> --------------------------------
>
> Key: CASSANDRA-3605
> URL: https://issues.apache.org/jira/browse/CASSANDRA-3605
> Project: Cassandra
> Issue Type: Bug
> Affects Versions: 1.0.5
> Environment: all
> Reporter: Zoltan Farkas
> Priority: Minor
>
> org.apache.cassandra.utils.Hex line 94:
> try
> {
> s = stringConstructor.newInstance(0, c.length, c);
> }
> catch (Exception e)
> {
> // Swallowing as we'll just use a copying constructor
> }
> this code does not comply with coding standard, caught exception needs to be rethrown as RuntimeException
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira