title: Synchronization on the local variables
body: <p>Today I was faced with the method <code>constructServiceUrl()</code> of the <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.jasig.cas/cas-client-core/3.1.10/org/jasig/cas/client/util/CommonUtils.java#CommonUtils.constructServiceUrl%28javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse,java.lang.String,java.lang.String,java.lang.String,boolean%29" rel="noreferrer"><code>org.jasig.cas.client.util.CommonUtils</code></a> class. I thought he was very strange:       </p>
  
  <pre><code>final StringBuffer buffer = new StringBuffer();
  
  synchronized (buffer)
  {
      if (!serverName.startsWith("https://") &amp;&amp; !serverName.startsWith("http://"))
      {
          buffer.append(request.isSecure() ? "https://" : "http://");
      }
  
      buffer.append(serverName);
      buffer.append(request.getRequestURI());
  
      if (CommonUtils.isNotBlank(request.getQueryString()))
      {
          final int location = request.getQueryString().indexOf(
                  artifactParameterName + "=");
  
          if (location == 0)
          {
              final String returnValue = encode ? response.encodeURL(buffer.toString()) : buffer.toString();
  
              if (LOG.isDebugEnabled())
              {
                  LOG.debug("serviceUrl generated: " + returnValue);
              }
  
              return returnValue;
          }
  
          buffer.append("?");
  
          if (location == -1)
          {
              buffer.append(request.getQueryString());
          }
          else if (location &gt; 0)
          {
              final int actualLocation = request.getQueryString()
                      .indexOf("&amp;" + artifactParameterName + "=");
  
              if (actualLocation == -1)
              {
                  buffer.append(request.getQueryString());
              }
              else if (actualLocation &gt; 0)
              {
                  buffer.append(request.getQueryString().substring(0, actualLocation));
              }
          }
      }
  }
  </code></pre>
  
  <p>Why did the author synchronizes a local variable?</p>