java - تعطيل تحذير في IntelliJ لخط واحد




intellij-idea warnings line (5)

لدي خط رمز Java حيث يعرض IntelliJ تحذيرًا. كيف أسكت التحذير في هذا الخط المعين ، دون التأثير على التحذيرات المعروضة في سطور أخرى؟

في هذا السؤال لا يهم ما هو الإنذار الفعلي: الآن أنا لا أسعى للحصول على نصيحة حول كيفية تحسين جودة جزء معين من Java البرمجية ، ولكن أريد أن أعرف بشكل عام كيفية منع IntelliJ من عرض تحذير على محدد خط مصدر جافا.


Answers

بالتوسع في الإجابة على رايان ستيوارت ، في IntelliJ ، استخدم Alt+Enter ، ثم حدد القائمة الفرعية الأولى ، ثم العنصر الأخير: Suppress for statement .

تحديث

باستخدام IntelliJ IDEA 13 ، لاحظت وجود عنصر إضافي في القائمة: "Suppress for statement with comment". سيستخدم هذا النمط //noinspection unchecked . إذا قمت بتحديد "Suppress for statement" ، فسيقوم @SuppressWarnings("unchecked") بإدراج هذا النص: @SuppressWarnings("unchecked") .


في IntelliJ 15 لا تقدم القوائم "لمبة صفراء" مضمنة والقوائم alt-enter لقمع التفتيش لخط واحد.

هناك المزيد من الخيارات عند تشغيل عمليات التفتيش عبر القائمة: Analyze -> Inspect Code...

ثم على لوحة الفحص ، يقدم الجانب الأيمن العديد من الخيارات. بعض النصوص في اللوحة اليمنى قابلة للنقر. لاحظ أنه عادةً ما تكون وظيفة حل المشكلة (الإصلاح السريع) متوفرة أيضًا.

(على ما يبدو لاحظت @ tino بالفعل هذا في تعليق ، لكنني فاتني تعليقه في المرة الأولى. أنا أضيف هذا كإجابة كاملة لجعل الشيء المهم الذي فاتني شخصيا أسهل العثور عليه.)


اعتمادا على التحذير يمكنك استخدام @SuppressWarnings . على سبيل المثال:

@SuppressWarnings("deprecation")
yourLineWhichIsDeprecated;

ألقِ نظرة على هذه الإجابة للحصول على قائمة طويلة جدًا من التحذيرات التي يمكنك منعها. تحقق من المشاركات الأخرى في هذا الموضوع لمزيد من التفاصيل.


في الغالب في IntelliJ ، يمكنك النقر فوق السطر و Alt+Enter ، وسيكون لديك خيارات لقمع التحذير ، من بين أمور أخرى.


Warning: mysql_connect(): Access denied for user 'name'@'host'

This warning shows up when you connect to a MySQL/MariaDB server with invalid or missing credentials (username/password). So this is typically not a code problem, but a server configuration issue.

  • See the manual page on mysql_connect("localhost", "user", "pw") for examples.

  • Check that you actually used a $username and $password .

    • It's uncommon that you gain access using no password - which is what happened when the Warning: said (using password: NO) .
    • Only the local test server usually allows to connect with username root , no password, and the test database name.

    • You can test if they're really correct using the command line client:
      mysql --user="username" --password="password" testdb

    • Username and password are case-sensitive and whitespace is not ignored. If your password contains meta characters like $ , escape them, or put the password in single quotes .

    • Most shared hosting providers predeclare mysql accounts in relation to the unix user account (sometimes just prefixes or extra numeric suffixes). See the docs for a pattern or documentation, and CPanel or whatever interface for setting a password.

    • See the MySQL manual on Adding user accounts using the command line. When connected as admin user you can issue a query like:
      CREATE USER 'username'@'localhost' IDENTIFIED BY 'newpassword';

    • Or use Adminer or WorkBench or any other graphical tool to create, check or correct account details.

    • If you can't fix your credentials, then asking the internet to "please help" will have no effect. Only you and your hosting provider have permissions and sufficient access to diagnose and fix things.

  • Verify that you could reach the database server, using the host name given by your provider:
    ping dbserver.hoster.example.net

    • Check this from a SSH console directly on your webserver. Testing from your local development client to your shared hosting server is rarely meaningful.

    • Often you just want the server name to be "localhost" , which normally utilizes a local named socket when available. Othertimes you can try "127.0.0.1" as fallback.

    • Should your MySQL/MariaDB server listen on a different port, then use "servername:3306" .

    • If that fails, then there's a perhaps a firewall issue. (Off-topic, not a programming question. No remote guess-helping possible.)

  • When using constants like eg DB_USER or DB_PASSWORD , check that they're actually defined .

    • If you get a "Warning: Access defined for 'DB_USER'@'host'" and a "Notice: use of undefined constant 'DB_PASS'" , then that's your problem.

    • Verify that your eg xy/db-config.php was actually included and whatelse.

  • Check for correctly set GRANT permissions .

    • It's not sufficient to have a username + password pair.

    • Each MySQL/MariaDB account can have an attached set of permissions.

    • Those can restrict which databases you are allowed to connect to, from which client/server the connection may originate from, and which queries are permitted.

    • The "Access denied" warning thus may as well show up for mysql_query calls, if you don't have permissions to SELECT from a specific table, or INSERT / UPDATE , and more commonly DELETE anything.

    • You can adapt account permissions when connected per command line client using the admin account with a query like:
      GRANT ALL ON yourdb.* TO 'username'@'localhost';

  • If the warning shows up first with Warning: mysql_query(): Access denied for user ''@'localhost' then you may have a php.ini-preconfigured account/password pair .

    • Check that mysql.default_user= and mysql.default_password= have meaningful values.

    • Oftentimes this is a provider-configuration. So contact their support for mismatches.

  • Find the documentation of your shared hosting provider:

  • Note that you may also have depleted the available connection pool . You'll get access denied warnings for too many concurrent connections. (You have to investigate the setup. That's an off-topic server configuration issue, not a programming question.)

  • Your libmysql client version may not be compatible with the database server. Normally MySQL and MariaDB servers can be reached with PHPs compiled in driver. If you have a custom setup, or an outdated PHP version, and a much newer database server, or significantly outdated one - then the version mismatch may prevent connections. (No, you have to investigate yourself. Nobody can guess your setup).

More references:

Btw, you probably don't want to use mysql_* functions anymore . Newcomers often migrate to mysqli , which however is just as tedious. Instead read up on PDO and prepared statements .
$db = new PDO("mysql:host=localhost;dbname=testdb", "username", "password");







java intellij-idea warnings line