Clojure

namespace function NPE if namespace does not exist

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: Backlog
  • Component/s: None
  • Labels:
    None

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

Activity

Hide
Assembla Importer added a comment -
Show
Assembla Importer added a comment - Converted from http://www.assembla.com/spaces/clojure/tickets/350
Hide
Assembla Importer added a comment -

david-mcneil said: This issue was addressed indirectly by ticket 334. Now the code behaves like this for keywords that reference non-existent namespaces:

(namespace ::x/y)

;=> java.lang.Exception: Invalid token: ::x/y

Seems that is fine, at least it is not an NPE.

-David

Show
Assembla Importer added a comment - david-mcneil said: This issue was addressed indirectly by ticket 334. Now the code behaves like this for keywords that reference non-existent namespaces: (namespace ::x/y) ;=> java.lang.Exception: Invalid token: ::x/y Seems that is fine, at least it is not an NPE. -David
Hide
Assembla Importer added a comment -

donmullen said: This is fixed, as David indicated - ::x/y is an invalid token.

Current message is:

Exception Invalid token: ::x/y clojure.lang.LispReader.interpretToken (LispReader.java:286)

Exception Unmatched delimiter: ) clojure.lang.LispReader$UnmatchedDelimiterReader.invoke (LispReader.java:1039)

Show
Assembla Importer added a comment - donmullen said: This is fixed, as David indicated - ::x/y is an invalid token. Current message is: Exception Invalid token: ::x/y clojure.lang.LispReader.interpretToken (LispReader.java:286) Exception Unmatched delimiter: ) clojure.lang.LispReader$UnmatchedDelimiterReader.invoke (LispReader.java:1039)

People

  • Assignee:
    Unassigned
    Reporter:
    Anonymous
Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: