ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "M Kim (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (IVY-1513) NullPointerException in addConfiguredMacrodef of Configurator.java
Date Mon, 16 Feb 2015 17:51:11 GMT

     [ https://issues.apache.org/jira/browse/IVY-1513?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

M Kim updated IVY-1513:
-----------------------
    Description: 
NullPointerException occurs in addConfiguredMacrodef of Configurator.java because the parameter
macrodef is null. However, this null value is returned from getCurrent() method which explicitly
returns null when objectStack field is empty. Therefore, NPE should be suitably handled where
getCurrent() is called. 

{code}
    public Object getCurrent() {
        return objectStack.isEmpty() ? null : ((ObjectDescriptor) objectStack.peek()).getObject();
//null is returned
    }

    public void endMacroDef() {
        addConfiguredMacrodef(((MacroDef) getCurrent()));
        objectStack.pop();
    }

    public void addConfiguredMacrodef(MacroDef macrodef) {
        macrodefs.put(macrodef.getName(), macrodef);
    }
{code}

<Stack Trace>
{code}
test(Test)java.lang.NullPointerException
at org.apache.ivy.util.Configurator.addConfiguredMacrodef(Configurator.java:749)
at org.apache.ivy.util.Configurator.endMacroDef(Configurator.java:744)
at Test.test(Test.java:20)
{code}

<Test Case>
{code}
public void test(){
  Configurator var = new Configurator();
  var.startMacroDef("macro");
  var.clear();
  var.endMacroDef();
}
{code}


  was:
NullPointerException occurs in addConfiguredMacrodef of Configurator.java because the parameter
macrodef is null. However, this null value is returned from getCurrent() method which explicitly
returns null when objectStack field is empty. Therefore, NPE should be suitably handled where
getCurrent() is called. 

{code}
    public Object getCurrent() {
        return objectStack.isEmpty() ? null : ((ObjectDescriptor) objectStack.peek()).getObject();
    }

    public void endMacroDef() {
        addConfiguredMacrodef(((MacroDef) getCurrent()));
        objectStack.pop();
    }

    public void addConfiguredMacrodef(MacroDef macrodef) {
        macrodefs.put(macrodef.getName(), macrodef);
    }
{code}

<Stack Trace>
{code}
test(Test)java.lang.NullPointerException
at org.apache.ivy.util.Configurator.addConfiguredMacrodef(Configurator.java:749)
at org.apache.ivy.util.Configurator.endMacroDef(Configurator.java:744)
at Test.test(Test.java:20)
{code}

<Test Case>
{code}
public void test(){
  Configurator var = new Configurator();
  var.startMacroDef("macro");
  var.clear();
  var.endMacroDef();
}
{code}



> NullPointerException in addConfiguredMacrodef of Configurator.java
> ------------------------------------------------------------------
>
>                 Key: IVY-1513
>                 URL: https://issues.apache.org/jira/browse/IVY-1513
>             Project: Ivy
>          Issue Type: Bug
>    Affects Versions: 2.4.0
>            Reporter: M Kim
>
> NullPointerException occurs in addConfiguredMacrodef of Configurator.java because the
parameter macrodef is null. However, this null value is returned from getCurrent() method
which explicitly returns null when objectStack field is empty. Therefore, NPE should be suitably
handled where getCurrent() is called. 
> {code}
>     public Object getCurrent() {
>         return objectStack.isEmpty() ? null : ((ObjectDescriptor) objectStack.peek()).getObject();
//null is returned
>     }
>     public void endMacroDef() {
>         addConfiguredMacrodef(((MacroDef) getCurrent()));
>         objectStack.pop();
>     }
>     public void addConfiguredMacrodef(MacroDef macrodef) {
>         macrodefs.put(macrodef.getName(), macrodef);
>     }
> {code}
> <Stack Trace>
> {code}
> test(Test)java.lang.NullPointerException
> at org.apache.ivy.util.Configurator.addConfiguredMacrodef(Configurator.java:749)
> at org.apache.ivy.util.Configurator.endMacroDef(Configurator.java:744)
> at Test.test(Test.java:20)
> {code}
> <Test Case>
> {code}
> public void test(){
>   Configurator var = new Configurator();
>   var.startMacroDef("macro");
>   var.clear();
>   var.endMacroDef();
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message