Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4087820
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:54:12+00:00 2026-05-20T18:54:12+00:00

Edit: I was able to fix it by making changing val to lazy val

  • 0

Edit: I was able to fix it by making changing val to lazy val in the MessageParser class. I forgot that I had previously tested it using def instead of val. Can someone make it clear why this change fixes it?

So, I am currently writing an IRC Server. I decided to use Scala’s Combinator Parser library to help me parse the messages. I’ve been able to correctly parse a message through a test program, but when I attempted to incorporate my parser into an echo server I already wrote I receive the following error message when I make a connection to my server:

Connected to the target VM, address: '127.0.0.1:55567', transport: 'socket'
Exception in thread "main" java.lang.ExceptionInInitializerError
    at IRCServer.main(IRCServer.scala)
Caused by: java.lang.NullPointerException
    at messages.MessageParser.<init>(MessageParser.scala:11)
    at net.Connection.<init>(Connection.scala:14)
    at net.Server.start(Server.scala:14)
    at IRCServer$.<init>(IRCServer.scala:12)
    at IRCServer$.<clinit>(IRCServer.scala)
    ... 1 more
Disconnected from the target VM, address: '127.0.0.1:55567', transport: 'socket'

The Connection class handles a listener Socket created from a ServerSocket

class Connection(socket: Socket) extends Thread {
    private val out = new PrintStream(socket.getOutputStream)
    private val in  = new BufferedReader(new InputStreamReader(socket.getInputStream))
    private val parser = new MessageParser
    override def run(): Unit = {
        var line = ""
        while({(line = in.readLine); line != null}) {
            Console.println("received: " + line)
            parser.parseLine(line.trim)
            out.println("out: " + line)
        }
    }

}

And the following is my MessageParser:

class MessageParser extends JavaTokenParsers {
    def parseLine(line :CharSequence) = {
        parseAll(message, line)
    }

    val message: Parser[Any] = opt(":"~prefix)~command~opt(params) ^^ (x=> {println("message: "+x)})
    val prefix: Parser[Any] = nick~"!"~user~"@"~host | servername ^^ (x=> {println("prefix: " +x)})
    val nick: Parser[Any] = letter~rep(letter | wholeNumber | special) ^^ (x=> {println("nick: " +x)})
    val special: Parser[Any] = "-" | "[" | "]" | "\\" | "`" | "^" | "{" | "}" ^^ (x=> {println("special: " +x)})
    val user: Parser[Any] = """[^\s@]+""".r ^^ (x=> {println("user: " +x)})
    val host: Parser[Any] = """[\w\.]+\w+""".r ^^ (x=> {println("host: " +x)})
    val servername: Parser[Any] = host ^^ (x=> {println("servername: " +x)})
    val command: Parser[Any] = """([A-Za-z]+)|([0-9]{3})""".r ^^ (x=> {println("command: " +x)})
    val params: Parser[Any] = rep(param)~opt(":"~tail) ^^ (x=> {println("params: " +x)})
    val param: Parser[Any] = """[^:][\S]*""".r
    val tail: Parser[Any] = """.*$""".r ^^ (x=> {println("tail: " +x)})
    val letter: Parser[Any] = """[A-Za-z]""".r ^^ (x=> {println("letter: " +x)})
}

I’m not quite sure what could be causing this. Hopefully I’m just being blind to something small.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:54:13+00:00Added an answer on May 20, 2026 at 6:54 pm

    lazy val values are populated as-needed; val values are populated in the order you specify. With a parser, earlier entries refer to later ones which don’t exist yet. So they’d better be lazy val or def (which one depends on the parser; the packrat parser likes lazy val, while the others usually assume def, but I’m not sure that they require it).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: I was able to fix the presentation thing by changing the NSLog to
EDIT - I was able to fix this problem using code from 'Farray' with
I have a textarea that I'm able to edit with the jeditable plugin but
I'm using vim to edit files that use a programming language where the end
I'm using class.upload.php to upload images to a page. It seems a script that
I want to be able to edit and delete resources myself, but not allow
I want to be able to edit how users paste strings and pictures. My
(Summary: My users need to be able to edit the structure of their dynamically
I would like the user to be able to edit the title of the
I am looking for a tool which will make able to edit parts of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.