<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Bug on bramp.net</title>
    <link>https://blog.bramp.net/</link>
    <description>Recent content in Bug on bramp.net</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-GB</language>
    <lastBuildDate>Tue, 02 Aug 2011 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://blog.bramp.net/tags/bug/" rel="self" type="application/rss+xml" />
    
    <item>
      <title>Google Chrome Javascript console.log bug?</title>
      <link>https://blog.bramp.net/post/2011/08/02/google-chrome-javascript-console.log-bug/</link>
      <pubDate>Tue, 02 Aug 2011 00:00:00 +0000</pubDate>
      
      <guid>https://blog.bramp.net/post/2011/08/02/google-chrome-javascript-console.log-bug/</guid>
      <description><p>I recently stumbled across this issue while debugging some Javascript. Take the following example code:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-javascript" data-lang="javascript"><span class="line"><span class="cl"><span class="kd">var</span> <span class="nx">array</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">6</span><span class="p">,</span><span class="mi">7</span><span class="p">,</span><span class="mi">8</span><span class="p">,</span><span class="mi">9</span><span class="p">,</span><span class="mi">10</span><span class="p">];</span>
</span></span><span class="line"><span class="cl"><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"><span class="k">while</span><span class="p">(</span><span class="nx">array</span><span class="p">.</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">	<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">i</span><span class="o">++</span><span class="p">,</span> <span class="nx">array</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">	<span class="c1">//alert(&#34;pause&#34;);
</span></span></span><span class="line"><span class="cl">	<span class="nx">array</span><span class="p">.</span><span class="nx">pop</span><span class="p">();</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><p>If you run it in your browser you would expect to see the following printed (in your Javascript console):</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">0 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
</span></span><span class="line"><span class="cl">1 [1, 2, 3, 4, 5, 6, 7, 8, 9]
</span></span><span class="line"><span class="cl">2 [1, 2, 3, 4, 5, 6, 7, 8]
</span></span><span class="line"><span class="cl">3 [1, 2, 3, 4, 5, 6, 7]
</span></span><span class="line"><span class="cl">4 [1, 2, 3, 4, 5, 6]
</span></span><span class="line"><span class="cl">5 [1, 2, 3, 4, 5]
</span></span><span class="line"><span class="cl">6 [1, 2, 3, 4]
</span></span><span class="line"><span class="cl">7 [1, 2, 3]
</span></span><span class="line"><span class="cl">8 [1, 2]
</span></span><span class="line"><span class="cl">9 [1]
</span></span></code></pre></div><p>However, I instead saw:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">1 []
</span></span><span class="line"><span class="cl">2 []
</span></span><span class="line"><span class="cl">3 []
</span></span><span class="line"><span class="cl">4 []
</span></span><span class="line"><span class="cl">5 []
</span></span><span class="line"><span class="cl">6 []
</span></span><span class="line"><span class="cl">7 []
</span></span><span class="line"><span class="cl">8 []
</span></span><span class="line"><span class="cl">9 []
</span></span></code></pre></div><p>The issue seems to be that console.log() does not log straight away. In fact it most likely logs in a background thread for performance reasons. Thus by the time it actually logs the array it has changed. I tested this in Firefox (with Firebug) and it logged everything correctly. I also tried slowing down the loop by adding a alert() call. That fixed the issue at the cost of a popup every iterations.</p>
<p>What really should happen is either</p>
<ul>
<li><code>console.log()</code> should block until the logging is complete</li>
<li><code>console.log()</code> should copy all objects to avoid them being changed after log() returns but before they are printed.</li>
<li>add a <code>console.flush()</code> and make me aware this race condition could occur.</li>
</ul>
<p>I filed this as a <a href="https://code.google.com/p/chromium/issues/detail?id=91303">bug report</a> on the Chromium site, but I suspect I should have filed it over at the Webkit site.</p>
<p>For the moment I came up with a “fix”. I copy the array before I log it, so in this case I do the following:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-javascript" data-lang="javascript"><span class="line"><span class="cl"><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">i</span><span class="o">++</span><span class="p">,</span> <span class="nx">array</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">0</span><span class="p">));</span>
</span></span></code></pre></div><p><strong>Update:</strong> I previously searched for this bug, but didn’t find it before writing this article. However, I have just found someone else had <a href="https://code.google.com/p/chromium/issues/detail?id=50316">reported</a> it a few days ago:</p>
</description>
    </item>
    
    <item>
      <title>Android Linux SDK revision 6 aapt library bug</title>
      <link>https://blog.bramp.net/post/2010/05/23/android-linux-sdk-revision-6-aapt-library-bug/</link>
      <pubDate>Sun, 23 May 2010 00:00:00 +0000</pubDate>
      
      <guid>https://blog.bramp.net/post/2010/05/23/android-linux-sdk-revision-6-aapt-library-bug/</guid>
      <description><p><strong>UPDATE – I <a href="http://code.google.com/p/android/issues/detail?id=8498">reported this bug</a> and it was promptly fixed the next day. Read the <a href="http://code.google.com/p/android/issues/detail?id=8498">bug report</a> for solution on how to fix.</strong></p>
<p><a href="http://android-developers.blogspot.com/2010/05/android-22-and-developers-goodies.html">Android 2.2</a> just came out and along with it came a updated set of <a href="http://developer.android.com/sdk/tools-notes.html">SDK tools</a>. I’ve been using these tools on Windows, but today I took my Linux laptop out and I’ve been sat in a <a href="http://www.juicafe.co.uk/">coffee shop</a> hyped up on caffeine but completely unproductive because I’m going round in circles with what I think is a bug.</p>
<p>So, I’m trying the <a href="http://developer.android.com/guide/developing/other-ide.html#libraryProject">new library feature</a>, where you can have a Android library project, which is referenced by one or more Android projects. This allows multiple projects to easily share the same code. The problem is when I set-up my Android project to use a library project I get the following error printed in my eclipse console:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">ERROR: Unknown option &#39;--auto-add-overlay&#39;
</span></span><span class="line"><span class="cl">Android Asset Packaging Tool
</span></span></code></pre></div><p>and the code fails to compile. If I remove the reference to the library project this error goes away.</p>
<p>The error is coming from the aapt command, which seems to be installed multiple times, once for each SDK version:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">$ locate -r <span class="s2">&#34;aapt</span>$<span class="s2">&#34;</span>
</span></span><span class="line"><span class="cl">/home/bramp/android-sdk-linux_86/platforms/android-3/tools/aapt
</span></span><span class="line"><span class="cl">/home/bramp/android-sdk-linux_86/platforms/android-4/tools/aapt
</span></span><span class="line"><span class="cl">/home/bramp/android-sdk-linux_86/platforms/android-7/tools/aapt
</span></span><span class="line"><span class="cl">/home/bramp/android-sdk-linux_86/platforms/android-8/tools/aapt
</span></span></code></pre></div><p>Checking each command I see that only versions 7 and 8 have the <em>–auto-add-overlay</em> option. Both my library and main projects are targeted at Android 1.6 (i.e. android-4). I tried re-targeting my main project to Android 2.2 (i.e. android-8) and the problem seems to go away.</p>
<p>So for the moment this seems an annoyance, but I can live with it by setting my target to 2.2. Hopefully Google will release a fix so I can still use the older targets with the new library feature.</p>
<p><strong>Just a quick update:</strong><br>
I noticed that on Windows all versions of the aapt tool support the ‘–auto-add-overlay’ option. So what I suspect has happened is that someone forgot to update the aapt binary for the old platforms.</p>
</description>
    </item>
    
  </channel>
</rss>
