Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

llegalArgumentException from servlet

 
mike zhang
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a servlet which has a help action class that handles its request and response objects and set some attribute with it. This servlet then forwards to a jsp page finally. In this servlets's action class, it handles some business logics like database access. So I have another database access class, in this class "DB.java"where DBFinder is a class that reads the Database information file and returns the Database name, port number, etc. The interesting and intriguing thing is:
if I comment line --(1) and use line 2, 3. it keeps giving me "java.lang.IllegalArgumentException".
if I comment line 2, 3 and use line 1, everything works fine.
Now the interesting thing is --
If I use a separate tester class to test , I found
dbFinder.get_DB_NAME()
does return "MyDatabase".

It seems it just can't be put here. I don't know what's the problem. can somebody help ???

Thanks,
Mike
- added code tags (MDC)
[ February 27, 2002: Message edited by: Mike Curwen ]
 
prabhat kumar
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can u post the code for DBFinder class?
 
mike zhang
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it reads a "myPropertyFile" which is like the follwoing format:
DATABASE_NAME=abc
...
Thanks,
Mike


-added code tags (MDC)
[ February 27, 2002: Message edited by: Mike Curwen ]
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mike,

Is there a reason you're not using a Properties object for this? It was made specifically for exactly what you're trying to do in DBFinder.

As for your IllegalArgumentException, can you provide the stack trace? There is nothing obvious that might be causing it.
[ February 27, 2002: Message edited by: Mike Curwen ]
 
prabhat kumar
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
u just need to use the properties to read that.

hope it will solve
 
mike zhang
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike and Prabhat,
Thank you so much for the help. It turned out that I made a silly mistake that I messed up with the file path, I gave a relative path and somehow it couldn't find it. After fixing that, it all worked well. Your help is highly appreciated.
Now, I have one more question here:
I just want to make sure that "myproperty.txt" file does NOT contain any variable name that is(are) identical to the system's existing ones, otherwise it will mess everything up. So I checked the SUN web, it says the following is the complete list of runtime system properties:
file.separator" File separator (for example, "/")

"java.class.path" Java classpath
"java.class.version" Java class version number
"java.home" Java installation directory
"java.vendor" Java vendor-specific string
"java.vendor.url" Java vendor URL
"java.version" Java version number
"line.separator" Line separator
"os.arch" Operating system architecture
"os.name" Operating system name
"os.version" Operating system version
"path.separator" Path separator (for example, ":")
"user.dir" User's current working directory
"user.home" User home directory
"user.name" User
Now, can I assume that as long as I DON'T give any property name same as any of above, it will be safe ??? So, I can feel free to write something like
...
PORT=7100
PORT_NUMBER=7100
SERVER=sunmachine
...
and don't need to worry about messing up any real system properties ?
Thanks,
Mike
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is... every user's system will be different. If you are running on Windows or on Solaris or on Linux, the system property values will be different, and perhaps there are more or less properties themselves. And that doesn't look anything close to a full list. Run this code to see what your own system properties are:

Beyond that issue, why would it mess up anything, unless you put them into the System property space by doing code like: Just don't do that, and you're fine.

And as a last question. You are using this in the context of a servlet. Is there any reason you are not using the facility provided to you by the servlet container? ( env-entry, context-param, init-param )
 
mike zhang
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Mike.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic