namespace function NPE if namespace does not exist

Description

The namespace function throws an NPE if the namespace of the symbol does not exist. For example:

(namespace ::x/y)
;=> NPE

The following patch changes corrects this. The resulting code throws an IllegalArgumentException with the message: "Namespace does not exist: x".

(Note: My Contributor's Agreement is in place, but since my request to join the Google clojure-dev group is still pending I decided to go ahead and submit the patch here.)

-David McNeil

====

From 5d65e5d9aabebf4ea5961e4e0bd8483618f8247e Mon Sep 17 00:00:00 2001
From: David McNeil <dem@dem-laptop.(none)>
Date: Sat, 15 May 2010 10:55:28 -0500
Subject: [PATCH] Avoid NPE and throw better exception if symbol's namespace does not exist.


src/jvm/clojure/lang/LispReader.java | 6 ++++--
1 files changed, 4 insertions, 2 deletions

diff --git a/src/jvm/clojure/lang/LispReader.java b/src/jvm/clojure/lang/LispReader.java
index 0bfae97..361b9cc 100644
— a/src/jvm/clojure/lang/LispReader.java
+++ b/src/jvm/clojure/lang/LispReader.java
@@ -302,9 +302,11 @@ private static Object matchSymbol(String s){
{
Symbol ks = Symbol.intern(s.substring(2));
Namespace kns;

  • if(ks.ns != null)
    + if(ks.ns != null) {
    kns = Compiler.namespaceFor(ks);

  • else
    + if(kns == null)
    + throw new IllegalArgumentException("Namespace does not exist: " + ks.ns);
    + } else
    kns = Compiler.currentNS();
    //auto-resolving keyword
    return Keyword.intern(kns.name.name,ks.name);

    • 1.6.3.3

Environment

None

Status

Assignee

Unassigned

Reporter

import

Labels

None

Approval

None

Patch

None

Fix versions

Priority

Configure