Code review comment: This is needed in two places because we don't handle the case where the namespace uri is defined using a variable reference and which is not a constant reference. In that case also we set the namespaceURI to be empty string. We decided to handle that case in a separately (different PR). So we need to have two checks here. Otherwise an invalid error would be thrown.

Code under review:
public void visit(BLangXMLNS xmlnsNode) {
        String nsURI = "";
        if (xmlnsNode.namespaceURI.getKind() == NodeKind.SIMPLE_VARIABLE_REF) {
            BLangSimpleVarRef varRef = (BLangSimpleVarRef) xmlnsNode.namespaceURI;
            if (Symbols.isFlagOn(varRef.symbol.flags, Flags.CONSTANT)) {
                nsURI = ((BConstantSymbol) varRef.symbol).value.toString();
                checkInvalidNameSpaceDeclaration(xmlnsNode.pos, xmlnsNode.prefix, nsURI);
            }
        } else {
            nsURI = (String) ((BLangLiteral) xmlnsNode.namespaceURI).value;
            checkInvalidNameSpaceDeclaration(xmlnsNode.pos, xmlnsNode.prefix, nsURI);
        }

        
        if (xmlnsNode.prefix.value == null) {
            xmlnsNode.prefix.value = XMLConstants.DEFAULT_NS_PREFIX;
        }

        Name prefix = names.fromIdNode(xmlnsNode.prefix);
        Location nsSymbolPos = prefix.value.isEmpty() ? xmlnsNode.pos : xmlnsNode.prefix.pos;
        BXMLNSSymbol xmlnsSymbol = Symbols.createXMLNSSymbol(prefix, nsURI, env.enclPkg.symbol.pkgID, env.scope.owner,
                                                             nsSymbolPos, getOrigin(prefix));
        xmlnsNode.symbol = xmlnsSymbol;

        
        
        
        BSymbol foundSym = symResolver.lookupSymbolInPrefixSpace(env, xmlnsSymbol.name);
        if ((foundSym.tag & SymTag.PACKAGE) != SymTag.PACKAGE) {
            foundSym = symTable.notFoundSymbol;
        }
        if (foundSym != symTable.notFoundSymbol) {
            dlog.error(xmlnsNode.pos, DiagnosticErrorCode.REDECLARED_SYMBOL, xmlnsSymbol.name);
            return;
        }

        
        
        defineSymbol(xmlnsNode.prefix.pos, xmlnsSymbol);
    }

Line commented on: checkInvalidNameSpaceDeclaration(xmlnsNode.pos, xmlnsNode.prefix, nsURI);

Revised code:
public void visit(BLangXMLNS xmlnsNode) {
        String nsURI = "";
        if (xmlnsNode.namespaceURI.getKind() == NodeKind.SIMPLE_VARIABLE_REF) {
            BLangSimpleVarRef varRef = (BLangSimpleVarRef) xmlnsNode.namespaceURI;
            if (Symbols.isFlagOn(varRef.symbol.flags, Flags.CONSTANT)) {
                nsURI = ((BConstantSymbol) varRef.symbol).value.toString();
                checkInvalidNameSpaceDeclaration(xmlnsNode.pos, xmlnsNode.prefix, nsURI);
            }
        } else {
            nsURI = (String) ((BLangLiteral) xmlnsNode.namespaceURI).value;
            checkInvalidNameSpaceDeclaration(xmlnsNode.pos, xmlnsNode.prefix, nsURI);
        }

        
        if (xmlnsNode.prefix.value == null) {
            xmlnsNode.prefix.value = XMLConstants.DEFAULT_NS_PREFIX;
        }

        Name prefix = names.fromIdNode(xmlnsNode.prefix);
        Location nsSymbolPos = prefix.value.isEmpty() ? xmlnsNode.pos : xmlnsNode.prefix.pos;
        BXMLNSSymbol xmlnsSymbol = Symbols.createXMLNSSymbol(prefix, nsURI, env.enclPkg.symbol.pkgID, env.scope.owner,
                                                             nsSymbolPos, getOrigin(prefix));
        xmlnsNode.symbol = xmlnsSymbol;

        
        
        
        BSymbol foundSym = symResolver.lookupSymbolInPrefixSpace(env, xmlnsSymbol.name);
        if ((foundSym.tag & SymTag.PACKAGE) != SymTag.PACKAGE) {
            foundSym = symTable.notFoundSymbol;
        }
        if (foundSym != symTable.notFoundSymbol) {
            dlog.error(xmlnsNode.pos, DiagnosticErrorCode.REDECLARED_SYMBOL, xmlnsSymbol.name);
            return;
        }

        
        
        defineSymbol(xmlnsNode.prefix.pos, xmlnsSymbol);
    }