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

Masatake Iwasaki edited comment on HTRACE-119 at 2/28/15 4:29 AM:
------------------------------------------------------------------

bq. Why allow double detach on NullScope, but not on other scopes? I guess one 
reason is so that you can turn off HTrace and not get exceptions from incorrect 
use of htrace.

The code below is not double detach. It is correct from user's perspective.
{code}
Span = Trace.startSpan("MySpan").detach();
...
{code}

Though it is correct, just passing this (or similar) code path more than twice 
may results in RuntimeException because startSpan returns NullSpan.INSTANCE 
always when there is no ongoing trace. {{detach}} of the singleton NullSpan 
instance may be called many times from completely independent and correct code 
paths.
{code}
  public static TraceScope startSpan(String description) {
    return startSpan(description, TrueIfTracingSampler.INSTANCE);
  }
{code}



was (Author: iwasakims):
bq. Why allow double detach on NullScope, but not on other scopes? I guess one 
reason is so that you can turn off HTrace and not get exceptions from incorrect 
use of htrace.

The code below is not double detach. It is correct from user's perspective.
{code}
Span = Trace.startSpan("MySpan").detach();
...
{code}

Though it is correct, just passing this (or similar) code path more than twice 
may results in RuntimeException because startSpan returns NullSpan.INSTANCE 
always when there is no ongoing trace. {{trace}} of the singleton NullSpan 
instance may be called many times from completely independent and correct code 
paths.
{code}
  public static TraceScope startSpan(String description) {
    return startSpan(description, TrueIfTracingSampler.INSTANCE);
  }
{code}


> detach of NullScope singleton should not fail
> ---------------------------------------------
>
>                 Key: HTRACE-119
>                 URL: https://issues.apache.org/jira/browse/HTRACE-119
>             Project: HTrace
>          Issue Type: Bug
>    Affects Versions: master
>            Reporter: Masatake Iwasaki
>            Assignee: Masatake Iwasaki
>         Attachments: HTRACE-119.001.patch
>
>
> The {{detach}} method of NullScope singleton is possible to be called 
> multiple times by users avoiding conditionals by the assumption that 
> NullScope#close and NullScope#detach results in no-op. Calling {{detach}} of 
> NullScope singleton multiple times throws RuntimeException by HTRACE-101 now.



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

Reply via email to