Scalac compiler doesn't create a .class file - scala

I am trying understand the error handling in scala.
I compiled the code as following
scalac sampleExceptionHandling.sc
I thought it would create a .class file and using javap command, I can look at the equivalent java code. For somereason, .class file isn't created. And no errors thrown either after executing Scalac command.
Any suggestion please?
import java.io.FileReader
import java.io.FileNotFoundException
import java.io.IOException
object Demo {
def main(args: Array[String]) {
try {
val f = new FileReader("input.txt")
} catch {
case ex: FileNotFoundException =>{
println("Missing file exception")
}
case ex: IOException => {
println("IO Exception")
}
}
}
}

It does create .class which is same as your class name not as your filename.
Following is the result of scalac sampleExceptionHandling.sc
$ ll
total 24
10909194 -rw-r--r-- 1 as18 prayagupd 936 Mar 15 10:00 Demo$.class
10909193 -rw-r--r-- 1 as18 prayagupd 565 Mar 15 10:00 Demo.class
10909167 -rw-r--r-- 1 as18 prayagupd 378 Mar 15 09:59 sampleExceptionHandling.sc
To run the class
$ scala Demo
Missing file exception
To see the bytecode,
$ javap -c Demo.class
Compiled from "sampleExceptionHandling.sc"
public final class Demo {
public static void main(java.lang.String[]);
Code:
0: getstatic #16 // Field Demo$.MODULE$:LDemo$;
3: aload_0
4: invokevirtual #18 // Method Demo$.main:([Ljava/lang/String;)V
7: return
}
And,
$ javap -c Demo$.class
Compiled from "sampleExceptionHandling.sc"
public final class Demo$ {
public static final Demo$ MODULE$;
public static {};
Code:
0: new #2 // class Demo$
3: invokespecial #12 // Method "<init>":()V
6: return
public void main(java.lang.String[]);
Code:
0: new #20 // class java/io/FileReader
3: dup
4: ldc #22 // String input.txt
6: invokespecial #25 // Method java/io/FileReader."<init>":(Ljava/lang/String;)V
9: astore 4
11: goto 35
14: astore_2
15: getstatic #30 // Field scala/Predef$.MODULE$:Lscala/Predef$;
18: ldc #32 // String IO Exception
20: invokevirtual #36 // Method scala/Predef$.println:(Ljava/lang/Object;)V
23: goto 35
26: astore_3
27: getstatic #30 // Field scala/Predef$.MODULE$:Lscala/Predef$;
30: ldc #38 // String Missing file exception
32: invokevirtual #36 // Method scala/Predef$.println:(Ljava/lang/Object;)V
35: return
Exception table:
from to target type
0 14 26 Class java/io/FileNotFoundException
0 14 14 Class java/io/IOException
}

Related

Netbeans not running PHPUnit tests

I am running PHP7.1 in the latest Netbeans version and am trying to run PHPUnit 6.5 along with it. When I run the tests in Netbeans, they are not executed and the output window gives the following stacktrace:
"C:\bin\phpunit.bat" "--colors" "--log-junit" "C:\Users\rwinkler\AppData\Local\Temp\nb-phpunit-log.xml" "C:\bin\phpunit.phar"
Fatal error: Uncaught PHPUnit\Runner\Exception: Class 'C:\bin\phpunit' could not be found in 'C:\bin\phpunit.phar'. in phar://C:/bin/phpunit.phar/phpunit/Runner/StandardTestSuiteLoader.php:102
Stack trace:
#0 phar://C:/bin/phpunit.phar/phpunit/Runner/BaseTestRunner.php(130): PHPUnit\Runner\StandardTestSuiteLoader->load('C:\\bin\\phpunit', 'C:\\bin\\phpunit....')
#1 phar://C:/bin/phpunit.phar/phpunit/Runner/BaseTestRunner.php(73): PHPUnit\Runner\BaseTestRunner->loadSuiteClass('C:\\bin\\phpunit', 'C:\\bin\\phpunit....')
#2 phar://C:/bin/phpunit.phar/phpunit/TextUI/Command.php(169): PHPUnit\Runner\BaseTestRunner->getTest('C:\\bin\\phpunit', 'C:\\bin\\phpunit....', Array)
#3 phar://C:/bin/phpunit.phar/phpunit/TextUI/Command.php(148): PHPUnit\TextUI\Command->run(Array, true)
#4 C:\bin\phpunit.phar(570): PHPUnit\TextUI\Command::main()
#5 {main}
thrown in phar://C:/bin/phpunit.phar/phpunit/Runner/StandardTestSuiteLoader.php on line 102
PHP Fatal error: Uncaught PHPUnit\Runner\Exception: Class 'C:\bin\phpunit' could not be found in 'C:\bin\phpunit.phar'. in phar://C:/bin/phpunit.phar/phpunit/Runner/StandardTestSuiteLoader.php:102
Stack trace:
#0 phar://C:/bin/phpunit.phar/phpunit/Runner/BaseTestRunner.php(130): PHPUnit\Runner\StandardTestSuiteLoader->load('C:\\bin\\phpunit', 'C:\\bin\\phpunit....')
#1 phar://C:/bin/phpunit.phar/phpunit/Runner/BaseTestRunner.php(73): PHPUnit\Runner\BaseTestRunner->loadSuiteClass('C:\\bin\\phpunit', 'C:\\bin\\phpunit....')
#2 phar://C:/bin/phpunit.phar/phpunit/TextUI/Command.php(169): PHPUnit\Runner\BaseTestRunner->getTest('C:\\bin\\phpunit', 'C:\\bin\\phpunit....', Array)
#3 phar://C:/bin/phpunit.phar/phpunit/TextUI/Command.php(148): PHPUnit\TextUI\Command->run(Array, true)
#4 C:\bin\phpunit.phar(570): PHPUnit\TextUI\Command::main()
#5 {main}
thrown in phar://C:/bin/phpunit.phar/phpunit/Runner/StandardTestSuiteLoader.php on line 102
Done.
My test is a sample test I pulled from a tutorial:
<?php
require_once 'PHPUnit/Autoload.php';
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class EmailTest extends TestCase
{
public function testCanBeCreatedFromValidEmailAddress(): void
{
$this->assertInstanceOf(
Email::class,
Email::fromString('user#example.com')
);
}
public function testCannotBeCreatedFromInvalidEmailAddress(): void
{
$this->expectException(InvalidArgumentException::class);
Email::fromString('invalid');
}
public function testCanBeUsedAsString(): void
{
$this->assertEquals(
'user#example.com',
Email::fromString('user#example.com')
);
}
}
Per xmike in the comments:
"i guess you have misconfigured Project properties -> Testing -> PHPUnit -> Use custom test suite (leave it empty) "

Unique Constraint Violation Magento 2

Very occasionally after a successful checkout the following error shows up on success page / logs:
SagePaySuiteLogger.Exception: Unique constraint violation found
I am using Ebizmarts Sage pay suite 1.2.4 with form integration and Magento 2.2.3 although believe have had the issue for other versions also. I am guessing this is a duplicate entry somehow however hoping for any additional information about what this may be caused by or how to fix.
Trace:
[2018-03-29 08:26:44] SagePaySuiteLogger.Exception: Unique constraint violation found
#0 /home/sites/magento/public_html/vendor/magento/framework/Model/AbstractModel.php(647): Magento\Framework\Model\ResourceModel\Db\AbstractDb->save(Object(Magento\Sales\Model\Order\Payment\Transaction))
#1 /home/sites/magento/public_html/vendor/ebizmarts/sagepaysuite/Model/OrderUpdateOnCallback.php(72): Magento\Framework\Model\AbstractModel->save()
#2 /home/sites/magento/public_html/vendor/ebizmarts/sagepaysuite/Controller/Form/Success.php(172): Ebizmarts\SagePaySuite\Model\OrderUpdateOnCallback->confirmPayment('B1B897CC-D94C-4...')
#3 /home/sites/magento/public_html/vendor/magento/framework/App/Action/Action.php(107): Ebizmarts\SagePaySuite\Controller\Form\Success->execute()
#4 /home/sites/magento/public_html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http))
#5 /home/sites/magento/public_html/vendor/magento/framework/Interception/Interceptor.php(138): Ebizmarts\SagePaySuite\Controller\Form\Success\Interceptor->___callParent('dispatch', Array)
#6 /home/sites/magento/public_html/vendor/magento/framework/Interception/Interceptor.php(153): Ebizmarts\SagePaySuite\Controller\Form\Success\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#7 /home/sites/magento/public_html/generated/code/Ebizmarts/SagePaySuite/Controller/Form/Success/Interceptor.php(26): Ebizmarts\SagePaySuite\Controller\Form\Success\Interceptor->___callPlugins('dispatch', Array, Array)
#8 /home/sites/magento/public_html/vendor/magento/framework/App/FrontController.php(55): Ebizmarts\SagePaySuite\Controller\Form\Success\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#9 /home/sites/magento/public_html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))
#10 /home/sites/magento/public_html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array)
#11 /home/sites/magento/public_html/vendor/magento/module-store/App/FrontController/Plugin/RequestPreprocessor.php(94): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#12 /home/sites/magento/public_html/vendor/magento/framework/Interception/Interceptor.php(135): Magento\Store\App\FrontController\Plugin\RequestPreprocessor->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#13 /home/sites/magento/public_html/vendor/magento/module-page-cache/Model/App/FrontController/BuiltinPlugin.php(73): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#14 /home/sites/magento/public_html/vendor/magento/framework/Interception/Interceptor.php(135): Magento\PageCache\Model\App\FrontController\BuiltinPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#15 /home/sites/magento/public_html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#16 /home/sites/magento/public_html/generated/code/Magento/Framework/App/FrontController/Interceptor.php(26): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, NULL)
#17 /home/sites/magento/public_html/vendor/magento/framework/App/Http.php(135): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#18 /home/sites/magento/public_html/vendor/magento/framework/App/Bootstrap.php(256): Magento\Framework\App\Http->launch()
#19 /home/sites/magento/public_html/pub/index.php(37): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor))
#20 {main}
Code:
This is thrown it seems in the below code:
try {
if (!$this->isModified($object)) {
$this->processNotModifiedSave($object);
$this->commit();
$object->setHasDataChanges(false);
return $this;
}
$object->validateBeforeSave();
$object->beforeSave();
if ($object->isSaveAllowed()) {
$this->_serializeFields($object);
$this->_beforeSave($object);
$this->_checkUnique($object);
$this->objectRelationProcessor->validateDataIntegrity($this->getMainTable(), $object->getData());
if ($this->isObjectNotNew($object)) {
$this->updateObject($object);
} else {
$this->saveNewObject($object);
}
$this->unserializeFields($object);
$this->processAfterSaves($object);
}
$this->addCommitCallback([$object, 'afterCommitCallback'])->commit();
$object->setHasDataChanges(false);
} catch (DuplicateException $e) {
$this->rollBack();
$object->setHasDataChanges(true);
throw new AlreadyExistsException(new Phrase('Unique constraint violation found'), $e);
} catch (\Exception $e) {
$this->rollBack();
$object->setHasDataChanges(true);
throw $e;
}
What does this error mean and how could i fix/debug my magento instance so this no longer occurs?
It may be because of the issue with orders related database entry like for example with the order increment id in main order table. Suppose a case where system tries to enter next order increment id 100000001 and if 100000001 is already available in the order table, then this issue will come.

How to log SQL query in Zend on Zend_Db_Statement_Exception

When an application error occures on my site and it is connected with malformed SQL query, I'd like to know the query to solve the problem. But it's not easy, when such an error occurs, information is given like this:
An error occurred
Application error
Exception information:
Message: SQLSTATE[42S22]: Column not found: 1054 Unknown column
'p.name' in 'where clause'
Stack trace:
#0 /var/www/ksiegarnia/library/Zend/Db/Statement.php(303): Zend_Db_Statement_Pdo->_execute(Array)
#1 /var/www/ksiegarnia/library/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#2 /var/www/ksiegarnia/library/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query(Object(Zend_Db_Table_Select), Array)
#3 /var/www/ksiegarnia/library/Zend/Db/Select.php(686): Zend_Db_Adapter_Pdo_Abstract->query(Object(Zend_Db_Table_Select))
#4 /var/www/ksiegarnia/library/Zend/Paginator/Adapter/DbSelect.php(142): Zend_Db_Select->query(2)
#5 /var/www/ksiegarnia/library/Zend/Paginator/Adapter/DbSelect.php(183): Zend_Paginator_Adapter_DbSelect->setRowCount(Object(Zend_Db_Table_Select))
#6 [internal function]: Zend_Paginator_Adapter_DbSelect->count()
#7 /var/www/ksiegarnia/library/Zend/Paginator.php(540): count(Object(Zend_Paginator_Adapter_DbTableSelect))
#8 /var/www/ksiegarnia/library/Zend/Paginator.php(1081): Zend_Paginator->getTotalItemCount()
#9 /var/www/ksiegarnia/library/Zend/Paginator.php(753): Zend_Paginator->_calculatePageCount()
#10 /var/www/ksiegarnia/application/modules/default/controllers/IndexController.php(702): Zend_Paginator->setItemCountPerPage(10)
#11 /var/www/ksiegarnia/library/Zend/Controller/Action.php(516): IndexController->searchadvancedAction()
#12 /var/www/ksiegarnia/library/Zend/Controller/Dispatcher/Standard.php(308): Zend_Controller_Action->dispatch('searchadvancedA...')
#13 /var/www/ksiegarnia/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#14 /var/www/ksiegarnia/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#15 /var/www/ksiegarnia/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#16 /var/www/ksiegarnia/public_html/index.php(32): Zend_Application->run()
#17 {main}
How to log an SQL query that caused the error?
I've found a quite complicated, but useful solution, which is adding the following code to ErrorController.php:
when the exception is of class Zend_Db_Statement_Exception, go to a specific line of trace, get the Zend_Db_Select argument that was used there and get parts of SQL clause (where, from, order, group etc.) from it and log them into a log file. Nasty, isn't it? ;) But works :)
Here is the code to be inserted into ErrorController.php
$thread_id = exec('echo $$');
if (get_class($errors->exception) == 'Zend_Db_Statement_Exception') {
$trace = $errors->exception->getTrace();
foreach(array('columns', 'from', 'where', 'order', 'group', 'limitcount', 'limitoffset', 'union') as $queryPartName) {
$parts = $trace[2]['args'][0]->getPart($queryPartName);
if ((is_array($parts) && !empty($parts)) ||
(!is_array($parts) && trim($parts) !== '')) {
$log->log($thread_id. "\t".strtoupper($queryPartName) .': ', $priority);
if (is_array($parts)) {
foreach($parts as $part)
$log->log($thread_id. "\t"."\t". (is_array($part) ? 'Array: '. implode(', ', $part) : $part), $priority);
} else
$log->log($thread_id. "\t"."\t". $parts, $priority);
}
}
}

MKMapView crashing with EXC_BAD_ACCESS

I have the following line of code which activates the breakpoint
[mapView addAnnotations:grabinstance.itemArray];
This crashing randomly. grabinstance.itemArray is fully populated always and is never changing at the time due to this bit of code only being called once the array is full. This particular time this was confirmed as 323 items in the array.
NSZombieEnabled doesn't find anything at all either.
The backtrace is below and line 1154 is the line above.
#0 0x0126a372 in _insert ()
#1 0x0126a312 in _splitNode ()
#2 0x0126a3b7 in _insert ()
#3 0x011db253 in -[MKAnnotationContainerView addAnnotation:] ()
#4 0x011dfc2e in -[MKAnnotationContainerView addAnnotations:] ()
#5 0x011b0b30 in -[MKMapView addAnnotations:] ()
#6 0x00009257 in -[BigViewController plotItems] (self=0x614de90, _cmd=0x16464f) at /Users/zzzz/Documents/iPhone Projects/BigProject/Classes/BigViewController.m:1154
#7 0x005336c1 in _nsnote_callback ()
#8 0x01c18f99 in __CFXNotificationPost_old ()
#9 0x01b9833a in _CFXNotificationPostNotification ()
#10 0x00529266 in -[NSNotificationCenter postNotificationName:object:userInfo:] ()
#11 0x00024071 in -[ItemGrabber parserDidEndDocument:] (self=0x617b540, _cmd=0x689aa3, parser=0xf6b4ab0) at /Users/zzzz/Documents/iPhone Projects/BigProject/Classes/ItemGrabber.m:267
You should check your annotations using CLLocationCoordinate2DIsValid():
if (CLLocationCoordinate2DIsValid(place.coordinate)) {
[_mapView addAnnotation:place];
} else {
NSLog(#"place %# has invalid coordinates", place.name);
}
Bug reported to Apple and as been acknowledged
I also had the same problem and i fixed it,The problem was with my locations,The objects in the array may not contain valid locations,They may be garbage values

iphone core data deletion causes a crash

I have a core-data object "entity" with 2 fields - "name" (a NSString *) and "type" (a EntityType). EntityType is another core data obect with 1 field - name (NSString *).
I am creating and deleting an entity object using the code similar in functionality to the following code -
Entity *e1 = [NSEntityDescription insertNewObjectForEntityName:"#Entity" inManagedObjectContext: context]
EntityType *type = [NSEntityDescription insertNewObjectForEntityName:"#EntityType" inManagedObjectContext: context]
e1.type = type;
Now I delete the entity object without assigning any values or saving to the persistent store.
if([e1.name length] == 0) {
[context deleteObject:e1];
NSError *nil;
if(![context:save &error] {
// log error
}
}
At this point I see a crash, when I try to delete and save the object.
(Terminating due to uncaught exception 'NSRangeException' reason: [NSCFArray removeObjectAtIndex]: index(0) beyond bounds (0)]
Any pointers/suggestions are much appreciated.
Here's the stack trace that was requested -
#0 0x3266bdf4 in objc_exception_throw ()
#1 0x32d73b32 in +[NSException raise:format:arguments:] ()
#2 0x32d73ad2 in +[NSException raise:format:] ()
#3 0x33f4a710 in _NSArrayRaiseBoundException ()
#4 0x33f7ba3c in -[NSCFArray removeObjectAtIndex:] ()
#5 0x30537dc6 in -[NSFetchedResultsController(PrivateMethods) _removeObjectInFetchedObjectsAtIndex:] ()
#6 0x3053b50a in -[NSFetchedResultsController(PrivateMethods) _postprocessDeletedObjects:] ()
#7 0x3053aa9a in -[NSFetchedResultsController(PrivateMethods) _managedObjectContextDidChange:] ()
#8 0x33f765d8 in _nsnote_callback ()
#9 0x32d9e510 in _CFXNotificationPostNotification ()
#10 0x33f741b2 in -[NSNotificationCenter postNotificationName:object:userInfo:] ()
#11 0x304b4388 in -[NSManagedObjectContext(_NSInternalNotificationHandling) _postObjectsDidChangeNotificationWithUserInfo:] ()
#12 0x3050768a in -[NSManagedObjectContext(_NSInternalChangeProcessing) _createAndPostChangeNotification:withDeletions:withUpdates:withRefreshes:] ()
#13 0x3049c2b0 in -[NSManagedObjectContext(_NSInternalChangeProcessing) _processRecentChanges:] ()
#14 0x304cb186 in -[NSManagedObjectContext save:] ()
#15 0x00006d5a in -[MyAppViewController goToMain] (self=0x11b730, _cmd=0x174b3) at /Users/Me/Projects/MyApp/Classes/MyAppViewController.m:611
2010-09-15 17:37:10.053 MyApp[1273:207] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray removeObjectAtIndex:]: index (0) beyond bounds (0)'
2010-09-15 17:37:10.066 MApp[1273:207] Stack: (
853417245,
845594132,
852966195,
852966099,
............
.............
The error is coming from the fetchedResults array of the FRC. I suspect this is caused by you not implementing the FRC delegate methods properly such that when the tableview tries to update, it tries to access the zero index of an empty array.
When you have an FRC attached to any context, the FRC will update itself automatically when you make any change to context such as deleting an object (that is what the notifications in the trace stack are doing, telling the FRC to update.)