« first day (1269 days earlier)      last day (3677 days later) » 

1:30 PM
Good morning, Java!
 
fge
Good morning milord
Using Guava yet? :p
 
I am looking into it. :P
I'm looking for places in my codebase where I can use Guava
 
fge
Everywhere you use Collections.unmodifiable*() --> Immutable*
Ohwell, you will know soon enough ;)
 
Anything else?
 
fge
Well, RangeMap as we discussed yesterday can be useful
You also have quite some niceties which made their way into Java 8: Function, Predicate, Supplier... Along with utility classes to transform etc (Iterables, Lists, etc)
And of course Multimap, and even Table
 
1:44 PM
What does Table do?
 
fge
Table<R, C, V>
A "generic matrix", sort of
 
Interesting.
 
fge
I use a lot of other stuff but in your context I don't know whether they would interest you
Ohwell, there is Closer of cours
s,$,e,
 
You know, there's an edit button.
 
2:08 PM
@Michael hi
 
2:18 PM
Hi @Nisha
 
2 days ago, by Michael
@Nisha Inside of the servlet, are you closing the Writer object that is used to generate the HTTP response body?
I just want to ask about it
 
@Michael @Nisha hello
 
0
Q: java.lang.IllegalStateException at production site

NishaI am getting below exception at production site. SEVERE: Servlet.service() for servlet jsp threw exception java.lang.IllegalStateException at com.liferay.portal.servlet.filters.gzip.GZipResponse.getWriter(GZipResponse.java:122) at javax.servlet.ServletResponseWrapper.getWriter(ServletRespons...

@DevCarlsberg hi
@Michael I am not clear why this exception came on production site only. And work perfectly on local and staging.
This is basically a vaadin application with liferay.
 
fge
@Nisha did you go and see the source at that GZipResponse.java file? And do you use it in your test environment as well?
 
This exception came while Querying the data. Is it possible that due to large data there is time out.
@fge Actually GZipResponce.java is the filter file in liferay source.
We have use it in test and prod environment
 
fge
2:28 PM
Well, what does the source say?
What is line 122?
Start there
 
@fge moreover it was working fine initially. exception occurs randomly
@Override
public PrintWriter getWriter() throws IOException {
if (_printWriter != null) {
return _printWriter;
}

if (_servletOutputStream != null) {
throw new IllegalStateException();
}

if (_log.isWarnEnabled()) {
_log.warn("Use getOutputStream for optimum performance");
}

_servletOutputStream = getOutputStream();

_printWriter = UnsyncPrintWriterPool.borrow(
new OutputStreamWriter(//_stream, _res.getCharacterEncoding()));
_servletOutputStream, StringPool.UTF8));

return _printWriter;
}
 
fge
Which still doesn't tell you what that line of that file is, isn't it? Apart that it throws an IllegalStateException
OK, so now you have more info
 
122 line is
if (_servletOutputStream != null) {
throw new IllegalStateException();
}
 
fge
OK, now go "up the stack"
Why is it expecting to be null here?
 
you mean to say output stream is null
 
fge
2:31 PM
And what does getOutputStream() does?
No, it is NOT null
And GZip Response expects it to be
The question is why
 
@Override
public ServletOutputStream getOutputStream() throws IOException {
if (_printWriter != null) {
throw new IllegalStateException();
}

if (_servletOutputStream == null) {
if (_gZipContentType) {
_servletOutputStream = _response.getOutputStream();
}
else {
if (_firefox && RSSThreadLocal.isExportRSS()) {
_unsyncByteArrayOutputStream =
new UnsyncByteArrayOutputStream();

_servletOutputStream = new GZipServletOutputStream(
_unsyncByteArrayOutputStream);
}
else {
_servletOutputStream = new GZipServletOutputStream(
I got this
 
fge
Uh, don't you have a link to the source file, rather?
 
fge
@Nisha wouldn't you be calling .getWriter() twice by mistake somewhere?
 
@fge I have one query
If this is the case then the same exception should come in local env as well
This is basically the report module.
we are firing query and populating data for diff reports.
 
fge
2:43 PM
@Nisha try on the liferay mailing list/forum/whatever? Honestly I have no idea
 
The same report with different combination and with comparatively less data work.
@fge ok. Thanks :)
 
3:00 PM
@fge Does Guava have a case-insensitive multimap class?
 
fge
@Michael no but it has Equivalence, which you can use
Multimap<Equivalence<String>, String> for instance
 
What does that do?
 
fge
For simple case insensitivity match this will be more simple of course
But basically it allows you to "redefine" equals()/hashcode() provided you .wrap() for inserts and tests
 
Oh nice.
That's exactly what I need.
 
fge
You just have to implement doHash() and doEquivalent()
 
3:06 PM
Got it.
 
fge
And in fact that would be a Multimap<Equivalence.Wrapper<String>, String>, sorry
Provided your Equivalence is named eq you would use eq.wrap(s) where s is the string
Uh, maybe there is more simple than that
Although I haven't used this way
You have Equivalence.onResultOf(Function)
So a simple Function<String, String>() { return s.toLowerCase() } (I know, bad syntax) can do the trick
 
I'm confused. >.<
Do I need to create an implementation of "Equivalence"?
 
fge
Say you have private static final Function<String, String> F = new Function<String, String>() { @Override public void apply(@Nullable final String input) { return input == null ? null : input.toLowerCase(); } };
Then you can create an Equivalence<String> eq = Equivalence.onResultOf(F);
It's shorter than having to write a full Equivalence
 
Function doesn't exist in the Guava API.
Nvm
 
fge
Yes it does
Eh
Java 8 stole it
As it did Predicate :p
And Supplier
 
3:17 PM
"Equivalence.onResultOf" isn't static.
 
fge
Ah crap
Sorry for the false hope
 
So once I create an implementation of "Equivalence", how do I insert values into the map?
 
fge
You grab an implementation of that Equivalence (make it a singleton), let's say eq, and you .put(eq.wrap(s), value)
Since Equivalence is basically immutable, you can have one private static final Equivalence for all your code
The keys would be Equivalence.Wrapper<String>
 
G morning!
 
Ah got it, thanks @fge.
@GustavoSuarez Hi @GustavoSuarez
@fge But that defeats the whole point.
I wanted a case-insensitive map class because I didn't want to have to call "toLowercase()" every time I pass a key into it.
Now, instead of calling "toLowerCase()", I'm calling "eq.wrap()". xD
I'd sub-class ArrayListMultimap if I could. :(
Just override the get/put methods.
 
fge
3:34 PM
Yeah, and what tells you that .putAll() would call .put()? ;)
With an Equivalence you are at least guaranteed of the results
You could always implement ForwardingMultimap
That's another solution...
But the problem remains that you'd have to override ALL methods to be sure
Sure, this is less code to write than eq.wrap() each time
Your choice ;)
You have a Forwarding* class for pretty much all Collections you can think of
 
That'll work, I think.
 
fge
Anyway, it is true that an Equivalence is a little overkill for a simple .toLowerCase(), but I prefer this way, for the very reason that if I delegate I am not sure which method I have to override and which ones I have to skip
And for my use case I didn't see myself implementing equals() and hashcode() again and again, heh
 
Ah.
Well for me, it was either call "toLowercase()" or call "eq.wrap()" xD
ForwardingMultimap works good.
It's basically what I was doing before (wrapping a Multimap), but cleaner.
Off to lunch, cya.
 
fge
3:50 PM
Uh, possible ClassCastException
You violate the .contains() contract
 
 
1 hour later…
4:56 PM
Hi
I want to get the number of days of one date, how do this and thanks
 
Anybody got any tips on catching NullPointerExceptions?
 
you refer in an object have a null value
 
fge
5:13 PM
@JoePerkins you don't catch NPEs, you crush them
 
 
2 hours later…
6:47 PM
Can I group multiple Maven sub projects under one folder in eclipse?
Can anybody help me with some Maven & eclipse questions?
 
Ash
If any users happen to know java , can you see any problem in this code ?         public ResultSet showQuestions(String tbl)
{
p=p+1;
try
	{
	String query="select * from "+ tbl + "where no = ? ";
	ps=con.prepareStatement(query);
	ps.setInt(1,p);
	rs=ps.executeQuery();
	System.out.println("values for p is  "+p);
	}
catch(Exception e)
	{
	System.out.println("error while trying to display the quiz database "+e);
	}
	return rs;
}
 
1 message moved from HTML / CSS / WebDesign
 
fge
@Ash: SQL injection (tbl), catch of Exception
@Ash: and where is rs declared?
 
Ash
@fge this is only the part of the whole program.I am getting an error in this method.
It says I have an error in my sql syntax
the exact error message :
the '=1' here comes from the value of p
@fge can you plz expand on that : I am a total noob in java.
or just point to some link ?
here is the full code:
package com;
import java.sql.*;
import java.io.*;
public class DBconnect
{
PreparedStatement ps=null;
Connection con=null;
int i=0;
int created=1;
int inserted=0;
ResultSet rs=null;
int p=0;
public DBconnect()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost/edify","root","ROOT");
}

catch(Exception e)
{
System.out.println("error in connection "+e);
}
}
public int createQuiz(String quizname)
{
try
{
String sql = "INSERT INTO quiz (name)" + "VALUES (?)";
 

« first day (1269 days earlier)      last day (3677 days later) »