My First Post      My Facebook Profile      My MeOnShow Profile      W3LC Facebook Page      Learners Consortium Group      Job Portal      Shopping @Yeyhi.com

Pages










Showing posts with label use. Show all posts
Showing posts with label use. Show all posts

Friday, May 29, 2020

PMD error Avoid printStackTrace use logger call instead

Suppose you have a simple Try catch block in Java eg:

try {
  testsReader.readTestConfigurationJson();
  testsReader.readDeclarativeTestJson();

} catch (IOException e) {
  e.printStackTrace();
}


Running Java PMD during compilation will give you following error:

<pmd xmlns="http://pmd.sourceforge.net/report/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sourceforge.net/report/2.0.0 http://pmd.sourceforge.net/report_2_0_0.xsd" version="6.8.0" timestamp="2020-05-29T14:37:13.048"> <file name="/Users/mfaiz/<path>/platform/integration/test/framework/controller/StartController.java"> <violation beginline="71" endline="71" begincolumn="7" endcolumn="25" rule="AvoidPrintStackTrace" ruleset="Best Practices"package="<path>.integration.test.framework.controller" class="StartController" method="start" externalInfoUrl="https://pmd.github.io/pmd-6.8.0/pmd_rules_java_bestpractices.html#avoidprintstacktrace" priority="3"> Avoid printStackTrace(); use a logger call instead. </violation> </file> </pmd>

This is basically a violation of AvoidPrintStackTrace rule.


But, if you remove the e.printStacktrace() then you will get following pmd error:

<pmd xmlns="http://pmd.sourceforge.net/report/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sourceforge.net/report/2.0.0 http://pmd.sourceforge.net/report_2_0_0.xsd" version="6.8.0" timestamp="2020-05-29T14:31:59.579"> <file name="/Users/mfaiz/<path>/integration/test/framework/controller/StartController.java"> <violation beginline="70" endline="72" begincolumn="7" endcolumn="5" rule="EmptyCatchBlock" ruleset="Error Prone" package="<path>test.framework.controller"class="StartController" method="start" externalInfoUrl="https://pmd.github.io/pmd-6.8.0/pmd_rules_java_errorprone.html#emptycatchblock" priority="3">Avoid empty catch blocks</violation> </file> </pmd>



Solution:

Hence, the best solution is to use a logger.
It means you should use logging framework like logback or log4j and instead of printing exceptions directly:

e.printStackTrace();
    you should log them using this frameworks' API:

Eg:  log.error("Ops!", e);
Logging frameworks give you a lot of flexibility, e.g. you can choose whether you want to log to console or file - or maybe skip some messages if you find them no longer relevant in some environment.


But if you are in initial stages of development and want to postpone logging at this time then you can do the following trick.

Think!!!!
I will update the trick in next post :)

Tuesday, February 28, 2017

CD with mapped mounted drive on network : CHDIR command


It has happened with me that I was able to succesfully mount a network drive and can freely access it using Windows file-system Explorer. But my script was not able to access it. Digging a step further, i noticed that I could not even CD to that drive on command prompt. Hence i finally wrote this blog post for anyone running into the similar issue.

Question : How do I change to a mapped network drive at the command line?

Issue:
Say, you have a networked drive mapped to "U:\"
Now you want to go to that drive from a command line.
However, when you try you get an error suggesting
C:>u: The system cannot find the drive specified.


Solution:
There are two aspects to the solution:
1. The Syntax to use CD command on Windows may be the cause. Remember that for changing directories you should use cd /d U: rather than just U:
2. You should first start using the map drive on command prompt. Command used to do that is as follows:
net use u:

See attached screenshot showing the error as well as what happened after solution.




C:\Users\mfaiz\Downloads>net use p:
Local name        p:
Remote name       \\sxa.xxx.xxx.com\ap-xxx
Resource type     Disk
The command completed successfully.

Friday, October 14, 2016

Does Quora API exist - How can I use Quora's API - How to use Quora API

There are many including me who ponder over questions like:
Is there a Quora API that dev can use
How to use Quora api
reading Quora programatically

Answer: There is no official Quora APIs till date. Period.


Although there is an unofficial version to it, but its in a nascent stage till recently. See: https://github.com/csu/quora-api. This API interface also uses PyQuora package. It is build in Python. Refer: https://github.com/csu/pyquora


Yeah! however you can directly parse using URL injections. You can also understand it in a way that Quora has exposed a JSON-based data API that allows users to access data about a currently logged-in user. However, the power is very limited.



For instance, to request particular fields about the currently logged-in user, you can add fields to a query string and append to http://api.quora.com/api/logged_in_user. Currently supported fields include:
  •     Inbox
  •     Followers
  •     Following
  •     Notifs, etc
And, that is why i referred to it as mere URL injections!


You can also read about specific details on a Quora post itself. The only Quora API appears to be located at Quora Extension API by Edmond Lau on Edmond Lau's Posts.


But, I have an advice for you all geeks. Use these hacks with caution. At the best, DO NOT try with your primary account. You shall also stand a chance to block your account.

Afterall, Spamming is not good for health dear!

*PS: This answer is also posted in an official Quora post itself.
Refer:  https://www.quora.com/unanswered/How-can-I-use-Quoras-API

Tuesday, January 24, 2012

Computer and Information Technology Applications

I have prepared a PPT that has the topic

Overview of Computer and INFORMATION technology as a Product


It deals with :

Introduction of Computer and Information Technology, its application, future innovations and the effect on Economy.


All are free to download and use the ppt and contents. A proper place in bibliography or reference is what best I can dream of, as of now.