lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dawid Weiss (Commented) (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LUCENE-3877) Lucene should not call System.out.println
Date Thu, 22 Mar 2012 07:52:43 GMT

    [ https://issues.apache.org/jira/browse/LUCENE-3877?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13235424#comment-13235424
] 

Dawid Weiss commented on LUCENE-3877:
-------------------------------------

My aspectj experiments from yesterday when JIRA was dead.

I applied that aspect just to see what happens.
{noformat}
ajc -sourceroots aspects \
   -inpath lucene-core-3.6-SNAPSHOT.jar \
   -d none \
   -cp aspectjrt.jar \
   -showWeaveInfo
{noformat}
Here's what I got:
{noformat}
Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.analysis.PorterStemmer'
(PorterStemmer.java:529) advised by before advice from
'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.analysis.PorterStemmer'
(PorterStemmer.java:534) advised by before advice from
'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.analysis.PorterStemmer'
(PorterStemmer.java:542) advised by before advice from
'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.index.CheckIndex' (CheckIndex.java:989)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.index.CheckIndex' (CheckIndex.java:996)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.index.CheckIndex' (CheckIndex.java:1003)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.index.CheckIndex' (CheckIndex.java:1012)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.index.CheckIndex' (CheckIndex.java:1013)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.index.CheckIndex' (CheckIndex.java:1038)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.index.CheckIndex' (CheckIndex.java:1043)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.index.CheckIndex' (CheckIndex.java:1047)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.index.CheckIndex' (CheckIndex.java:1056)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.index.CheckIndex' (CheckIndex.java:1057)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.index.CheckIndex' (CheckIndex.java:1062)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.index.CheckIndex' (CheckIndex.java:1071)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.index.CheckIndex' (CheckIndex.java:1073)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.index.CheckIndex' (CheckIndex.java:1074)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.index.CheckIndex' (CheckIndex.java:1077)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.index.CheckIndex' (CheckIndex.java:1079)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.index.CheckIndex' (CheckIndex.java:1081)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.index.CheckIndex' (CheckIndex.java:1082)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.index.CheckIndex' (CheckIndex.java:1085)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.err)' in
Type 'org.apache.lucene.index.IndexUpgrader' (IndexUpgrader.java:55)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.err)' in
Type 'org.apache.lucene.index.IndexUpgrader' (IndexUpgrader.java:56)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.err)' in
Type 'org.apache.lucene.index.IndexUpgrader' (IndexUpgrader.java:57)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.err)' in
Type 'org.apache.lucene.index.IndexUpgrader' (IndexUpgrader.java:58)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.err)' in
Type 'org.apache.lucene.index.IndexUpgrader' (IndexUpgrader.java:59)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.err)' in
Type 'org.apache.lucene.index.IndexUpgrader' (IndexUpgrader.java:60)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.err)' in
Type 'org.apache.lucene.index.IndexUpgrader' (IndexUpgrader.java:61)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.err)' in
Type 'org.apache.lucene.index.IndexUpgrader' (IndexUpgrader.java:62)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.err)' in
Type 'org.apache.lucene.index.IndexUpgrader' (IndexUpgrader.java:65)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.index.IndexUpgrader' (IndexUpgrader.java:81)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.index.IndexUpgrader' (IndexUpgrader.java:86)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.err)' in
Type 'org.apache.lucene.queryParser.FastCharStream'
(FastCharStream.java:102) advised by before advice from
'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.queryParser.QueryParser'
(QueryParser.java:1159) advised by before advice from
'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.queryParser.QueryParser'
(QueryParser.java:1165) advised by before advice from
'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.queryParser.QueryParserTokenManager'
(QueryParserTokenManager.java:42) advised by before advice from
'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.store.LockStressTest' (LockStressTest.java:37)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.store.LockStressTest' (LockStressTest.java:58)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.store.LockStressTest'
(LockStressTest.java:100) advised by before advice from
'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.store.LockStressTest'
(LockStressTest.java:104) advised by before advice from
'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.store.LockVerifyServer'
(LockVerifyServer.java:45) advised by before advice from
'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.store.LockVerifyServer'
(LockVerifyServer.java:53) advised by before advice from
'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.store.LockVerifyServer'
(LockVerifyServer.java:72) advised by before advice from
'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.store.LockVerifyServer'
(LockVerifyServer.java:78) advised by before advice from
'spikes.NoSysOuts' (NoSysOuts.aj:6)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.store.LockVerifyServer'
(LockVerifyServer.java:84) advised by before advice from
'spikes.NoSysOuts' (NoSysOuts.aj:6)
{noformat}
Many of these are in static main methods and here's where
aspectj-based solution can be superior to handcoding; because we can
do this:
{code}
   pointcut ignored():
       withincode(public static void main(String[]));

   before(): within(org.apache.lucene..*) &&
             get(static PrintStream System.*) &&
             !ignored()
   {
       throw new RuntimeException("Attempted sysout/syserr/sysin access.");
   }
{code}
applied again:
{noformat}
Join point 'field-get(java.io.PrintStream java.lang.System.err)' in
Type 'org.apache.lucene.index.IndexUpgrader' (IndexUpgrader.java:55)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:16)

Join point 'field-get(java.io.PrintStream java.lang.System.err)' in
Type 'org.apache.lucene.index.IndexUpgrader' (IndexUpgrader.java:56)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:16)

Join point 'field-get(java.io.PrintStream java.lang.System.err)' in
Type 'org.apache.lucene.index.IndexUpgrader' (IndexUpgrader.java:57)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:16)

Join point 'field-get(java.io.PrintStream java.lang.System.err)' in
Type 'org.apache.lucene.index.IndexUpgrader' (IndexUpgrader.java:58)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:16)

Join point 'field-get(java.io.PrintStream java.lang.System.err)' in
Type 'org.apache.lucene.index.IndexUpgrader' (IndexUpgrader.java:59)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:16)

Join point 'field-get(java.io.PrintStream java.lang.System.err)' in
Type 'org.apache.lucene.index.IndexUpgrader' (IndexUpgrader.java:60)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:16)

Join point 'field-get(java.io.PrintStream java.lang.System.err)' in
Type 'org.apache.lucene.index.IndexUpgrader' (IndexUpgrader.java:61)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:16)

Join point 'field-get(java.io.PrintStream java.lang.System.err)' in
Type 'org.apache.lucene.index.IndexUpgrader' (IndexUpgrader.java:62)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:16)

Join point 'field-get(java.io.PrintStream java.lang.System.err)' in
Type 'org.apache.lucene.index.IndexUpgrader' (IndexUpgrader.java:65)
advised by before advice from 'spikes.NoSysOuts' (NoSysOuts.aj:16)

Join point 'field-get(java.io.PrintStream java.lang.System.err)' in
Type 'org.apache.lucene.queryParser.FastCharStream'
(FastCharStream.java:102) advised by before advice from
'spikes.NoSysOuts' (NoSysOuts.aj:16)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.queryParser.QueryParserTokenManager'
(QueryParserTokenManager.java:42) advised by before advice from
'spikes.NoSysOuts' (NoSysOuts.aj:16)
{noformat}
IndexUpgrader has a printUsage() method so we can exclude these by
name only (no access/ static restriction):
{code}
   pointcut ignored():
       withincode(public static void main(String[])) ||
       withincode(              void printUsage(..));
{code}
and then we're left with:
{noformat}
Join point 'field-get(java.io.PrintStream java.lang.System.err)' in
Type 'org.apache.lucene.queryParser.FastCharStream'
(FastCharStream.java:102) advised by before advice from
'spikes.NoSysOuts' (NoSysOuts.aj:17)

Join point 'field-get(java.io.PrintStream java.lang.System.out)' in
Type 'org.apache.lucene.queryParser.QueryParserTokenManager'
(QueryParserTokenManager.java:42) advised by before advice from
'spikes.NoSysOuts' (NoSysOuts.aj:17)
{noformat}
and these are:
{code}
   } catch (IOException e) {
     System.err.println("Caught: " + e + "; ignoring.");
   }
{code}
and:
{code}
 /** Debug output. */
 public  java.io.PrintStream debugStream = System.out;
{code}
This is perhaps the worst cast as it assigns System.out to another
field and then uses that to call printlns.

Both of which can be excluded, of course. AspectJ is fun. It's a pity
it never gained more traction.
                
> Lucene should not call System.out.println
> -----------------------------------------
>
>                 Key: LUCENE-3877
>                 URL: https://issues.apache.org/jira/browse/LUCENE-3877
>             Project: Lucene - Java
>          Issue Type: Bug
>            Reporter: Michael McCandless
>             Fix For: 3.6, 4.0
>
>         Attachments: IllegalSystemTest.java, IllegalSystemTest.java, SystemPrintCheck.java
>
>
> We seem to have accumulated a few random sops...
> Eg, PairOutputs.java (oal.util.fst) and MultiDocValues.java, at least.
> Can we somehow detect (eg, have a test failure) if we accidentally leave errant System.out.println's
(leftover from debugging)...?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


Mime
View raw message