From: Robin Rosenberg <robin.rosenberg.lists@dewire.com>
To: "Shawn O. Pearce" <spearce@spearce.org>
Cc: git@vger.kernel.org
Subject: Re: [EGIT PATCH 2/5] quickdiff - Don't add GitDocument as repository listener more than once
Date: Sun, 5 Apr 2009 23:41:15 +0200 [thread overview]
Message-ID: <200904052341.15590.robin.rosenberg.lists@dewire.com> (raw)
In-Reply-To: <20090405202400.GO23521@spearce.org>
söndag 05 april 2009 22:24:00 skrev "Shawn O. Pearce" <spearce@spearce.org>:
> Robin Rosenberg <robin.rosenberg@dewire.com> wrote:
> > Doing so was very costly and led to sessions being locked
> > for a long time while refreshing the reference document used
> > by Eclipse's quickdiff feature.
> ...
> > --- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
> > +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
> > @@ -1132,6 +1132,7 @@ public File getWorkDir() {
> > * @param l
> > */
> > public void addRepositoryChangedListener(final RepositoryListener l) {
> > + assert !listeners.contains(l);
> > listeners.add(l);
> > }
> >
> > @@ -1150,6 +1151,7 @@ public void removeRepositoryChangedListener(final RepositoryListener l) {
> > * @param l
> > */
> > public static void addAnyRepositoryChangedListener(final RepositoryListener l) {
> > + assert !allListeners.contains(l);
> > allListeners.add(l);
> > }
>
> That's a race condition. The two collections are Vectors so another
> thread can add the listener between your assertion point and the
> add call.
That would be another programming error, to add the same listener from different threads. Hopefully it would be caught on the next run. Adding synchronized might be too much since I cannot disable it by disabling assert.
> Also, if this really is considered to be very bad behavior on the
> part of the application, maybe these should be real tests with
> exceptions thrown, so they can't be disabled when assertions are
> turned off in the JRE?
It's usually not terribly bad, but what happens isn't well defined. If it happens it's a programming error. Especially now that the API bans it.
Asserts are for detecting programming errors during program test. If the tests are good enough there will never be a reason for this assert to fail and so it won't be necessary in deployed code. We could probably have lots more of these
declarations of assumptions, most of which would be less obvious than this simple test.
In particular asserts are for detecting bad conditions the programmer controls (or should control). Anything that can be the result of user actions or depending on the runtime environment should have non assert tests.
-- robin
prev parent reply other threads:[~2009-04-05 21:42 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-02 18:46 [EGIT PATCH 0/5] Quickdiff improvements Robin Rosenberg
2009-04-02 18:46 ` [EGIT PATCH 1/5] Make the equals method work for AnyObjectId, not just ObjectId Robin Rosenberg
2009-04-02 18:46 ` [EGIT PATCH 2/5] quickdiff - Don't add GitDocument as repository listener more than once Robin Rosenberg
2009-04-02 18:46 ` [EGIT PATCH 3/5] Move dcocument to repository mapping to GitDocument Robin Rosenberg
2009-04-02 18:46 ` [EGIT PATCH 4/5] Update Quickdiff tracing statements Robin Rosenberg
2009-04-02 18:46 ` [EGIT PATCH 5/5] Cache resolved ids in quickdiff document for faster update Robin Rosenberg
2009-04-05 20:36 ` Shawn O. Pearce
2009-04-05 21:40 ` Robin Rosenberg
2009-04-05 21:43 ` Shawn O. Pearce
2009-04-05 20:24 ` [EGIT PATCH 2/5] quickdiff - Don't add GitDocument as repository listener more than once Shawn O. Pearce
2009-04-05 21:41 ` Robin Rosenberg [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200904052341.15590.robin.rosenberg.lists@dewire.com \
--to=robin.rosenberg.lists@dewire.com \
--cc=git@vger.kernel.org \
--cc=spearce@spearce.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).